Skip to content

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.

  1. Reuse the previously created payment_token_ab.js file in your project directory.

  2. Ensure the code is as follows.

    const xrpl = require('xrpl');
    async function paymentTokenAB() {
    // Connect to the Testnet server
    const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233');
    await client.connect();
    // Set Alice's wallet
    const senderWallet = xrpl.Wallet.fromSecret('alice_wallet_secret_here');
    // Set Bob's wallet address
    const 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 code
    const amount = '100'; // Amount of tokens to send
    const response = await client.submitAndWait(
    {
    TransactionType: 'Payment', // Payment
    Account: senderWallet.address, // Alice's address
    Destination: recipientWalletAddress, // Bob's address
    Amount: {
    issuer: issuerWalletAddress, // Token issuer's address (Charlie)
    currency: currencyCode, // DOJ
    value: amount, // 100
    },
    },
    { wallet: senderWallet } // Authenticate with Alice's wallet
    );
    // Output the result to the console
    console.log('Transaction result:', response);
    // Call the client.disconnect() method to disconnect from the server
    client.disconnect();
    }
    paymentTokenAB().catch(console.error);
    1. Enter Alice’s testnet secret key in alice_wallet_secret_here.
    2. Enter Bob’s testnet address in bob_wallet_address_here.
    3. Enter Charlie’s testnet address in charlie_wallet_address_here.

Run the Script

  1. Run the following command in the command line to execute the script.

    Terminal window
    node payment_token_ab.js
  2. 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.