EN
Build-along · 20 min

Your first payment on testnet

Guide · SPC
  1. 1Install xrpl.js
    The JavaScript library for the XRP Ledger, from npm.terminal
    npm install xrpl
  2. 2Connect to testnet
    Testnet XRP has no value. The same code reaches mainnet with a mainnet server URL.index.mjs
    import { Client, xrpToDrops } from "xrpl"
    
    const client = new Client("wss://s.altnet.rippletest.net:51233")
    await client.connect()
  3. 3Get two funded wallets
    The testnet faucet creates and funds a throwaway account. One sends, one receives.index.mjs
    const { wallet } = await client.fundWallet()
    const { wallet: friend } = await client.fundWallet()
    
    console.log(wallet.address, friend.address)
  4. 4Send 10 XRP
    autofill adds the fee, sequence and last ledger. submitAndWait returns once the transaction is in a validated ledger.index.mjs
    const prepared = await client.autofill({
      TransactionType: "Payment",
      Account: wallet.address,
      Amount: xrpToDrops("10"),
      Destination: friend.address,
    })
    const signed = wallet.sign(prepared)
    const result = await client.submitAndWait(signed.tx_blob)
  5. 5Read the result
    tesSUCCESS means the payment applied. The fee is destroyed, not paid to anyone.index.mjs
    console.log(result.result.meta.TransactionResult)
    console.log(await client.getXrpBalance(friend.address))
    
    await client.disconnect()