Token Transfer Between Users 2 | XRPL Development in JavaScript Level 1
In the previous chapter, we successfully enabled the Rippling feature for Charlie’s account, the issuer of the DOJ
tokens.
In XRPL, transferring tokens between users other than the issuer is usually not permitted, but if the Rippling
feature is enabled in the issuer’s account, users (Alice and Bob) should be able to transfer tokens to each other.
※ It is not that Alice and Bob are directly interacting with each other, but rather adjusting balances through Charlie.
Prerequisites
This guide proceeds with the following characters:
- Charlie (Token Issuer)
- Alice (Token Recipient 1) ※ Currently holds 1000 DOJ
- Bob (Token Recipient 2)
Create the Script
The following is a script to send tokens from Alice to Bob.
-
Reuse the previously created
payment_token_ab.js
file in your project directory. -
Ensure the code is as follows.
const xrpl = require('xrpl');async function paymentTokenAB() {// Connect to the Testnet serverconst client = new xrpl.Client('wss://s.altnet.rippletest.net:51233');await client.connect();// Set Alice's walletconst senderWallet = xrpl.Wallet.fromSecret('alice_wallet_secret_here');// Set Bob's wallet addressconst recipientWalletAddress = 'bob_wallet_address_here';// Set the wallet address of the token issuer (Charlie)const issuerWalletAddress = 'charlie_wallet_address_here';const currencyCode = 'DOJ'; // Token currency codeconst amount = '100'; // Amount of tokens to sendconst response = await client.submitAndWait({TransactionType: 'Payment', // PaymentAccount: senderWallet.address, // Alice's addressDestination: recipientWalletAddress, // Bob's addressAmount: {issuer: issuerWalletAddress, // Token issuer's address (Charlie)currency: currencyCode, // DOJvalue: amount, // 100},},{ wallet: senderWallet } // Authenticate with Alice's wallet);// Output the result to the consoleconsole.log('Transaction result:', response);// Call the client.disconnect() method to disconnect from the serverclient.disconnect();}paymentTokenAB().catch(console.error);- Enter Alice’s testnet secret key in
alice_wallet_secret_here
. - Enter Bob’s testnet address in
bob_wallet_address_here
. - Enter Charlie’s testnet address in
charlie_wallet_address_here
.
- Enter Alice’s testnet secret key in
Run the Script
-
Run the following command in the command line to execute the script.
Terminal window node payment_token_ab.js -
Check result in the console .
Terminal window {id: 12,result: {Account: 'rQr8KfkCQcpqvFwmRspDoaL36reZhcdaeA',Amount: {currency: 'DOJ',issuer: 'rh8xETfGs1Ktizj9EXZb5QpW4aqk8bWUSU',value: '100'},DeliverMax: {currency: 'DOJ',issuer: 'rh8xETfGs1Ktizj9EXZb5QpW4aqk8bWUSU',value: '100'},Destination: 'rDNVaJJSp9iQmHC8YAAwHytnLP9aXEPhDw',Fee: '12',Flags: 0,LastLedgerSequence: 476082,Sequence: 474068,SigningPubKey: 'ED2924DBD08E093DD7FC9C35B8DCEBD74CA4C8349D68D7BF566AD6C2533B8BB865',TransactionType: 'Payment',TxnSignature: '51A2FC9136890DA4CEE45C54B81CBD9DA6266F99D190C96CE6E0E43FDC8A0DB2659804EB7C25A6992F01A0484DF3931E6131B5C9C356B1CCAA87D7B5D34EF401',ctid: 'C00743A0002D0001',date: 768406122,hash: '9E5EECCBE9D4CB8897783FB763EC715BD0BB763DFBF12E6DBD4FB5ED255783DB',inLedger: 476064,ledger_index: 476064,meta: {AffectedNodes: [Array],TransactionIndex: 45,TransactionResult: 'tecPATH_DRY' // Failure},validated: true},type: 'response'}Again, the transfer failed. Why?
In such cases, there may be issues with the account settings, so let’s check the status of the trust line using the wallet address of the issuer, Charlie.