DEV Community

Cover image for Your first payload (XUMM PHP SDK)
Wietse Wind
Wietse Wind

Posted on

Your first payload (XUMM PHP SDK)

3. Your first payload

Now that we've established a connection to the XUMM platform using the SDK, it's time to send something we can sign.
We'll send a "transaction template" to the XUMM platform, called a Payload. The lifecycle of a Payload is explained in
more detail in the XUMM API documentation.

First, create a payload by instantiating an instance of Xrpl\XummSdkPhp\Payload\Payload. It must contain a
transaction body array formatted as per XRP ledger specifications. It can
contain a user token, options, and some custom metadata.

3.1 Create a payload

Our first payload will be a Payment transaction type. This is a very minimal example of a payload you can send to XUMM:

$payment = new Xrpl\XummSdkPhp\Payload\Payload(
    [
        'TransactionType' => 'Payment',
        'Destination' => 'rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ', // Use your own address here
    ],
);
Enter fullscreen mode Exit fullscreen mode

If, like in the minimal example above, no amount is entered, the end user will be able to select the currency and amount
to send in XUMM after opening the sign request. You could also add more details to your payload, as per the following
example:

$payment = new Payload(
    transactionBody: [
        'TransactionType' => 'Payment',
        'Destination' => 'rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ', // Use your own address here
        'Amount' => '10000',
    ],
    options: new Options(
        immutable: true
    )
    customMeta: new CustomMeta(
        uniqid(),
        'Hi! Can you pay me please? Thanks! ❤️',
    )
);
Enter fullscreen mode Exit fullscreen mode

3.2 Send the payload

Now you can pass your Payload object to XummSdk::createPayload and show the result:

$createdPayment = $sdk->createPayload($payment);
$url = $createdPayment->next->always;
echo "Sign request: ${url}\n";
Enter fullscreen mode Exit fullscreen mode

Re-run your script to see it work! You can now follow the URL in the result and scan the QR code to sign the request,
or reject it.

The first time you send a user a sign request, they'll always have to scan the QR code. Once they've signed it, you can
obtain a user token for that user and send them push notifications on future sign requests! Let's see how that's done
in the next chapter:

Next: 4. Subscribe to live status updates

--

Credits: thank you Pauline!

Top comments (1)

Collapse
 
codewithharsh1 profile image
Harsh Jain

Hey, Great job . How is geekster.in/ . I found it to be way cheaper and they provides 100 % placement to their students.