Send XRP

This tutorial explains how to send a direct XRP Payment using xrpl.js for JavaScript, xrpl-py for Python, xrpl4j for Java or XRPL_PHP for PHP. First, we step through the process with the XRP Ledger Testnet. Then, we compare that to the additional requirements for doing the equivalent in production.

Prerequisites

To interact with the XRP Ledger, you need to set up a dev environment with the necessary tools. This tutorial provides examples using the following options:

- JavaScript with the xrpl.js library. See Get Started Using JavaScript for setup steps.
- Python with the xrpl-py library. See Get Started using Python for setup steps.
- Java with the xrpl4j library. See Get Started Using Java for setup steps.

Send a Payment on the Test Net

1. Get Credentials

To transact on the XRP Ledger, you need an address and secret key, and some XRP. The address and secret key look like this:

// Example credentials
const wallet = xrpl.Wallet.fromSeed("sn3nxiW7v8KXzPzAqzyHXbSSKNuN9")
console.log(wallet.address) // rMCcNuTcajgw7YTgBy1sys3b89QqjUrMpH

The secret key shown here is for example only. For development purposes, you can get your own credentials, pre-funded with XRP.

When you're building production-ready software, you should use an existing account, and manage your keys using a secure signing configuration.

2. Connect to a Testnet Server

First, you must connect to an XRP Ledger server so you can get the current status of your account and the shared ledger. You can use this information to automatically fill in some required fields of a transaction. You also must be connected to the network to submit transactions to it.

The following code connects to a public Testnet servers:

// You can also use a script tag in browsers or require('xrpl') in Node.js
import xrpl from 'xrpl'

// Define the network client
const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233")
await client.connect()

// ... custom code goes here

// Disconnect when done (If you omit this, Node.js won't end the process)
client.disconnect()