Build-along · 20 min
Your first payment on testnet
Guide · SPC- 1Install xrpl.jsThe JavaScript library for the XRP Ledger, from npm.terminal
npm install xrpl
- 2Connect to testnetTestnet 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() - 3Get two funded walletsThe 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) - 4Send 10 XRPautofill 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) - 5Read the resulttesSUCCESS 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()