Last active
October 20, 2020 14:32
-
-
Save WietseWind/4d844eb3a77bdca59cdb14c3e511d894 to your computer and use it in GitHub Desktop.
XUMM SDK: payload create & subscribe, await signed payload & retrieve user token (to Push our next payload)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {XummSdk} = require('xumm-sdk') | |
const Sdk = new XummSdk('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', '...') | |
const main = async () => { | |
const appInfo = await Sdk.ping() | |
console.log(appInfo.application.name) | |
// Please change the destination account to an account (and possibly: DestinationTag) | |
// you own, or you'll be testing sending a small amount of XRP to the XRPL Labs team ;) | |
const request = { | |
"TransactionType": "Payment", | |
"Destination": "rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ", | |
"Amount": "10000", | |
"Memos": [ | |
{ | |
"Memo": { | |
"MemoData": "F09F988E20596F7520726F636B21" | |
} | |
} | |
] | |
} | |
const subscription = await Sdk.payload.createAndSubscribe(request, event => { | |
console.log('New payload event:', event.data) | |
if (event.data.signed === true) { | |
// No need to console.log here, we'll do that below | |
return event.data | |
} | |
if (event.data.signed === false) { | |
// No need to console.log here, we'll do that below | |
return false | |
} | |
}) | |
console.log(subscription.created) | |
/** | |
* Now let's wait until the subscription resolved (by returning something) | |
* in the callback function. | |
*/ | |
const resolveData = await subscription.resolved | |
if (resolveData.signed === false) { | |
console.log('The sign request was rejected :(') | |
} | |
if (resolveData.signed === true) { | |
console.log('Woohoo! The sign request was signed :)') | |
/** | |
* Let's fetch the full payload end result, and get the issued | |
* user token, we can use to send our next payload per Push notification | |
*/ | |
const result = await Sdk.payload.get(resolveData.payload_uuidv4) | |
console.log('User token:', result.application.issued_user_token) | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment