Skip to content

Getting XRP for Development Use | Introduction to JavaScript

Testnet allows you to obtain XRP, the native token, for development purposes.

There are two main methods.

The following site allows you to acquire XRP by specifying an address.

If you want to send to the account address you created earlier by code, you can use the tool at bithomb.com.

If you want to get XRP while creating an address, go on and create an account below.

While it is better to use a tool for efficiency and convenience, you can also get XRP using code.

  1. Create a new file called faucet.js in your project directory.

  2. Paste the following code into faucet.js.

    async function faucet() {
    try {
    // XRPL Testnet Faucet URL
    const faucetUrl = 'https://faucet.altnet.rippletest.net/accounts';
    // Send POST request using Fetch API
    const response = await fetch(faucetUrl, {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json'
    }
    });
    if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
    }
    const data = await response.json();
    console.log('Wallet Address:', data.account.address);
    console.log('Secret:', data.account.secret);
    console.log('Balance:', data.balance); // display the amount of XRP granted in the test net
    } catch (error) {
    console.error('Error requesting XRP:', error.message);
    }
    }
    faucet();
  1. Run script by executing the following command on the command line.

    Terminal window
    node faucet.js
  2. If successful, you will see the following in the console.

    Terminal window
    Wallet Address: rDt3T3ifG96eKS4pkZyUxhYt8rTSpPDauf
    Secret: sEdTYR4byoAWLJUqFCGQsZsAX6ni9tc
    data: {
    account: {
    xAddress: 'XVBX4Scdqqvh8WukxJjvoNCSQ5CvZPCvZUPuaXaqZ2JuxH9',
    address: 'rDt3T3ifG96eKS4pkZyUxhYt8rTSpPDauf', // address
    classicAddress: 'rDt3T3ifG96eKS4pkZyUxhYt8rTSpPDauf'
    },
    amount: 100, // 100XRP has been obtained
    transactionHash: '6FBE1C1215B8B3D0765D3CEC2FD48EE2BBC073DB8A960A92CA0485986CFE226C',
    seed: 'sEdTYR4byoAWLJUqFCGQsZsAX6ni9tc' // secret key
    }