arrow-left

All pages
gitbookPowered by GitBook
1 of 6

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Xumm.payload { … }

Payloads are the primary reason for the XUMM API (thus this SDK) to exist.

An XRPL transaction "template" can be posted to the XUMM API. Your transaction tample to sign (so: your "sign request") will be persisted at the XUMM API backend. We now call it a a Payload. XUMM app user(s) can open the Payload (sign request) by scanning a QR code, opening deeplink or receiving push notification and resolve (reject or sign) on their own device.

A payload can contain an XRPL transaction template. Some properties may be omitted, as they will be added by the XUMM app when a user signs a transaction. A simple payload may look like this:

{
  txjson: {
    TransactionType : 'Payment',
    Destination : 'rwiETSee2wMz3SBnAG8hkMsCgvGy9LWbZ1',
    Amount: '1337'
  }
}

As you can see the payload looks like a regular XRPL transaction, wrapped in an txjson object, omitting the mandatory Account, Fee and Sequence properties. They will be added containing the correct values when the payload is signed by an app user.

Optionally (besides txjson) a payload can contain these properties ():

  • options to define payload options like a return URL, expiration, etc.

  • custom_meta to add metadata, user insruction, your own unique ID, ...

  • user_token

A more complex payload . A can be found in:

Instead of providing a txjson transaction, a transaction formatted as HEX blob (string) can be provided in a txblob property.

to push the payload to a user (after obtaining a user specific token)
TS definitionarrow-up-right
could look like thisarrow-up-right
reference for payload options & custom metaarrow-up-right
Payloads (sign requests)

create( … )

To create a payload, a txjson XRPL transaction can be provided. Alternatively, a transaction formatted as HEX blob (string) can be provided in a txblob property.

hashtag
Example contents of a payload

circle-info

Take a look at the and possible replacement variables for the Return URLs.

The response of a Sdk.payload.create() operation, looks like this:

The next.always URL is the URL to send the end user to, to scan a QR code or automatically open the XUMM app (if on mobile). If a user_token has been provided as part of the payload data provided to Sdk.payload.create(), you can see if the payload has been pushed to the end user. A button "didn't receive a push notification" could then take the user to the next.no_push_msg_received URL. The

Alternatively user routing / instruction flows can be custom built using the QR information provided in the refs object, and a subscription for live status updates (opened, signed, etc.) using a WebSocket client can be setup by connecting to the refs.websocket_status URL. Please note: this SDK already offers subscriptions. There's no need to setup your own WebSocket client:

hashtag
Object

API Docs for more information about payloads object contentsarrow-up-right
createAndSubscribe( … )
{
  txjson: {
    TransactionType: "Payment",
    Destination: "r...",
    Amount: "1000000"
  },
  options: {
    return_url: {
      app: "https://sample.test/?...",
      web: "https://sample.test/?id={id}"
    },
    force_network: "MAINNET"
  },
  custom_meta: {
    identifier: "123123",
    instruction: "Please sign this to..."
  }
}
{
  "uuid": "1289e9ae-7d5d-4d5f-b89c-18633112ce09",
  "next": {
    "always": "https://xumm.app/sign/1289e9ae-7d5d-4d5f-b89c-18633112ce09",
    "no_push_msg_received": "https://xumm.app/sign/1289e9ae-7d5d-4d5f-b89c-18633112ce09/qr"
  },
  "refs": {
    "qr_png": "https://xumm.app/sign/1289e9ae-7d5d-4d5f-b89c-18633112ce09_q.png",
    "qr_matrix": "https://xumm.app/sign/1289e9ae-7d5d-4d5f-b89c-18633112ce09_q.json",
    "qr_uri_quality_opts": ["m", "q", "h"],
    "websocket_status": "wss://xumm.app/sign/1289e9ae-7d5d-4d5f-b89c-18633112ce09"
  },
  "pushed": true
}
async Sdk.payload.create (
  payload: CreatePayload,
  returnErrors: boolean = false
): Promise<CreatedPayload | null>

get( … )

To get payload details, status and if resolved & signed: results (transaction, transaction hash, etc.) you can get() a payload.

Note! Please don't use polling! The XUMM API offers Webhooks (configure your Webhook endpoint in the Developer Consolearrow-up-right) or use a subscription to receive live payload updates (for non-SDK users: Webhooksarrow-up-right).

You can get() a payload by:

  • Payload UUID

  • Passing a created Payload object (see: Sdk.payload.create)

If a payload can't be fetched (eg. doesn't exist), null will be returned, unless a second param (boolean) is provided to get the SDK to throw an Error in case a payload can't be retrieved:

hashtag
Object

const payload = await Sdk.payload.get("aaaaaaaa-bbbb-cccc-dddd-1234567890ab");
await Sdk.payload.get("aaaaaaaa-bbbb-cccc-dddd-1234567890ab", true)
const newPayload: XummTypes.CreatePayload = {txjson: {...}}
const created: XummTypes.CreatedPayload = await Sdk.payload.create(newPayload)
const payload: XummTypes.XummPayload = await Sdk.payload.get(created)
async Sdk.payload.get (
  payload: string | CreatedPayload,
  returnErrors: boolean = false
): Promise<XummPayload | null>

createAndSubscribe( … )

The <PayloadAndSubscription>arrow-up-right object is basically a <PayloadSubscription>arrow-up-right object with the created payload results in the created property:

All information that applies on Sdk.payload.create() and Sdk.payload.subscribe() applies. create( … ) / subscribe( … ). For the contents of a Payload, see the API Docs for more information about payloads object contentsarrow-up-right. Differences are:

  1. The input for a Sdk.payload.createAndSubscribe() call isn't a payload UUID / existing payload, but a payload to create.

  2. The response object also contains (<PayloadAndSubscription>.created) the response obtained when creating the payload.

hashtag
Example code

hashtag
Object

cancel( … )

To cancel a payload, provide a payload UUID (string), a <XummPayload> (by performing a Sdk.payload.get() first) or a <CreatedPayload> (by using the response of a Sdk.payload.create() call). By cancelling an existing payload, the payload will be marked as expired and can no longer be opened by users.

Please note: if a user already opened the payload in XUMM APP, the payload cannot be cancelled: the user may still be resolving the payload in the XUMM App, and should have a chance to complete that process.

A response (generic API types herearrow-up-right) looks like:

{
  result: {
    cancelled: boolean;
    reason: XummCancelReason;
  }
  meta: XummPayloadMeta;
  custom_meta: XummCustomMeta;
}

hashtag
Object

subscribe( … )

  • Returning non-void in the callback function passed to the Sdk.payload.subscribe() method

  • Manually calling <PayloadSubscription>.resolve() on the object returned by the Sdk.payload.subscribe() method

async Sdk.payload.cancel (
  payload: string | XummPayload | CreatedPayload,
  returnErrors: boolean = false
): Promise<DeletedPayload | null>
The subscription will be closed by either:

Status updates can be processed by providing a callback function to the Sdk.payload.subscribe() method. Alternatively, the (by the Sdk.payload.subscribe() method) returned raw websocket can be used to listen for WebSocket onmessage events.

More information about the status update events & sample event data: Status updates

  • The payload is opened by a XUMM App user (webpage)

  • The payload is opened by a XUMM App user (in the app)

  • Payload expiration updates (remaining time in seconds)

  • The payload was resolved by rejecting

  • The payload was resolved by accepting (signing)

To subscribe to live payload status updates, the XUMM SDK can setup a WebSocket connection and monitor live status events. Emitted events include:

hashtag
Payload subscriptions: live updates

If a callback function is not provided, the subscription will stay active until the <PayloadSubscription>.resolve() method is called manually, eg. based on handling <PayloadSubscription>.websocket.onmessage events.

When a callback function is provided, for every payload specific event the callback function will be called with <SubscriptionCallbackParams>arrow-up-right.

The <SubscriptionCallbackParams>.data property contains parsed JSON containing event information.

Either by calling <SubscriptionCallbackParams>.resolve() or by returning a non-void value in the callback function the subscription will be ended, and the <PayloadSubscription>.resolved promise will resolve with the value returned or passed to the <SubscriptionCallbackParams>.resolve() method.

Resolving (by returning non-void in the callback or calling resolve() manually) closes the WebSocket client the XUMM SDK sets up 'under the hood'.

The <PayloadSubscription>arrow-up-right object looks like this:

hashtag
Object

xumm.payload.createAndSubscribe({
  TransactionType: 'Payment',
  Destination: 'rfHn6cB5mmqZ6fHZ4fdemCDSxqLTijgMwo',
  Amount: String(1000000) // one million drops, 1 XRP
}, eventMessage => {
  if (Object.keys(eventMessage.data).indexOf('opened') > -1) {
    // Update the UI? The payload was opened.
  }
  if (Object.keys(eventMessage.data).indexOf('signed') > -1) {
    // The `signed` property is present, true (signed) / false (rejected)
    return eventMessage
  }
})
  .then(({ created, resolved }) => {
    console.log('Payload URL:', created.next.always)
    console.log('Payload QR:', created.refs.qr_png)

    return resolved // Return payload promise for the next `then`
  })
  .then(payload => console.log('Payload resolved', payload))
  // This is where you can do `xumm.payload.get(...)` to fetch details
async Sdk.payload.createAndSubscribe (
    payload: CreatePayload,
    callback?: onPayloadEvent
  ): Promise<PayloadAndSubscription>
{
  payload: XummPayload,
  resolved: Promise<unknown> | undefined
  resolve: (resolveData?: unknown) => void
  websocket: WebSocket
}
async Sdk.payload.subscribe (
  payload: string | XummPayload | CreatedPayload,
  callback?: onPayloadEvent
): Promise<PayloadSubscription>