Once payload is signed and a valid transaction is made, it is crucial to check for the transaction on main/live XRP ledger network.
For this we will be making use of a npm package: xrpl-txdata
Page Contents
Installing xrpl-txdata
npm install xrpl-txdata
Once this package is installed on your system, you can verify the transaction on live XRP ledger locally. “Locally” because the xrpl-txdata package will be installed locally on your machine.
Video Tutorial: Verify The Transaction on Mainnet: XUMM SDK
[youtube https://www.youtube.com/watch?v=kkGFMiX8bCY]
Why do we need to verify transaction on main XRP Ledger?
1. The end user signed the request successfully in XUMM, but with a key that is no longer valid for a certain account (because multisign has been configured, an account has been rekeyed, etc.)
2. The user sent a Partial Payment (e.g., sending EUR to deliver XRP, while the owned amount of EUR was insufficient due to exchange rate slippage).
3. The user tried to trick you into accepting a testnet payment, by signing with a funded Testnet account.
Source Code: Verify The Transaction on Mainnet: XUMM SDK
const {XummSdk} = require('xumm-sdk') const {TxData} = require('xrpl-txdata') const Sdk = new XummSdk('xumm-app-id', 'xumm-app-secret') const Verify = new TxData() const main = async() => { const request = { "txjson": { "TransactionType": "Payment", "Destination": "rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ", "Amount": "1000000" }, "user_token": "343a2f1e-8160-4984-a0f0-208086509617" } const subscription = await Sdk.payload.createAndSubscribe(request, event => { //console.log('New payload event',event.data) if(Object.keys(event.data).indexOf('signed') > -1) { return event.data } }) console.log('sign request 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('The sign request was Signed!!') const result = await Sdk.payload.get(resolveData.payload_uuidv4) const VerifiedResult = await Verify.getOne(result.response.txid) console.log('On ledger Balance ',VerifiedResult.balanceChanges) } } main()
Output of above code
sign request URL https://xumm.app/sign/b51bda5e-ebfe-48fe-b7ba-75797147c837 Pushed Yes On ledger Balance { rHdkzpxr3VfabJh9tUEDv7N4DJEsA4UioT : [{counterparty: '', currency: 'XRP', value: '-1.000012'}], rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ : [{counterparty: '', currency: 'XRP', value: '1'}] }
We are interested in On ledger Balance output. Here the first address is that of sender and the second address is that of receiver. So in this transaction 1.000012 XRP was sent by the end user and 0.000012 XRP was the network fee. Also note that the transaction fee will not be distributed to miners in XRPL, but instead it gets burnt permanently, reducing the over all supply of XRP.
Transaction verification Code Explained
We import xrpl-txdata package into our nodejs application, using require keyword. Next we create an instance of it called Verify.
Once the sign request is signed we get the transaction ID. i.e., we get the transaction ID only when the transaction is done.
So once we programmatically know that the transaction is made(by looking into signed: true key value in the output), we check the transaction on main/live XRP ledger, using following code:
console.log('The sign request was Signed!!') const result = await Sdk.payload.get(resolveData.payload_uuidv4) const VerifiedResult = await Verify.getOne(result.response.txid) console.log('On ledger Balance ',VerifiedResult.balanceChanges)
The instance Verify has a method called getOne() which checks the transaction on live XRP ledger, if we provide it with the transaction ID.
Switching from Testnet to Mainnet inside XUMM App
Open XUMM app present in your mobile phone. Navigate to Settings tab. Go to Advanced section. Then click on Node under the label XRP Ledger node and Explorer. Here you can switch between Main net and Test net. These are Main XRP ledger network and Test XRP ledger networks.
xrpl-txdata checks only against live XRP Ledger
Since xrpl-txdata checks only against live/main XRP ledger network, if you’re using testnet to send payments, it’ll throw error message that the transaction is not found on the main XRPL network – as your transactions will be present on test XRPL network and not on main/live XRPL network.
That’s it! You made it
If you’re this far into learning about XUMM SDK and working with XRP Ledger, then you might consider building some app, even if it’s just a hobby project.
For full “XUMM SDK/API” free video tutorial list visit: Working With XUMM SDK/API: XRPL