Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Created October 20, 2020 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WietseWind/6c6a3aefc551927ca42e73745e56a062 to your computer and use it in GitHub Desktop.
Save WietseWind/6c6a3aefc551927ca42e73745e56a062 to your computer and use it in GitHub Desktop.
XUMM Sign Request & on ledger transaction balance changes
const {XummSdk} = require('xumm-sdk')
const {TxData} = require('xrpl-txdata')
const Sdk = new XummSdk('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', '...')
const Verify = new TxData()
const main = async () => {
const appInfo = await Sdk.ping()
console.log(appInfo.application.name)
const request = {
"txjson": {
"TransactionType": "Payment",
"Destination": "rMdG3ju8pgyVh29ELPWaDuA74CpWW6Fxns",
"DestinationTag": 1700585980,
"Amount": "1000000"
},
"user_token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
const subscription = await Sdk.payload.createAndSubscribe(request, event => {
console.log('New payload event:', event.data)
// The event data contains a property 'signed' (true or false), return :)
if (Object.keys(event.data).indexOf('signed') > -1) {
return event.data
}
})
console.log('New payload created, URL:', subscription.created.next.always)
console.log(' > Pushed:', subscription.created.pushed ? 'yes' : 'no')
const resolveData = await subscription.resolved
if (resolveData.signed === false) {
console.log('The sign request was rejected :(')
} else {
console.log('Woohoo! The sign request was signed :)')
/**
* Let's fetch the full payload end result and check for
* a transaction hash, to verify the transaction on ledger later.
*/
const result = await Sdk.payload.get(resolveData.payload_uuidv4)
const verifiedResult = await Verify.getOne(result.response.txid)
console.log('On ledger balance changes:', verifiedResult.balanceChanges)
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment