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.
Obtain by specifying an address
Section titled “Obtain by specifying an address”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.
If you want to get it by code
Section titled “If you want to get it by code”While it is better to use a tool for efficiency and convenience, you can also get XRP using code.
Create Script
Section titled “Create Script”-
Create a new file called
faucet.js
in your project directory. -
Paste the following code into
faucet.js
.async function faucet() {try {// XRPL Testnet Faucet URLconst faucetUrl = 'https://faucet.altnet.rippletest.net/accounts';// Send POST request using Fetch APIconst 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();
Run script
Section titled “Run script”-
Run script by executing the following command on the command line.
Terminal window node faucet.js -
If successful, you will see the following in the console.
Terminal window Wallet Address: rDt3T3ifG96eKS4pkZyUxhYt8rTSpPDaufSecret: sEdTYR4byoAWLJUqFCGQsZsAX6ni9tcdata: {account: {xAddress: 'XVBX4Scdqqvh8WukxJjvoNCSQ5CvZPCvZUPuaXaqZ2JuxH9',address: 'rDt3T3ifG96eKS4pkZyUxhYt8rTSpPDauf', // addressclassicAddress: 'rDt3T3ifG96eKS4pkZyUxhYt8rTSpPDauf'},amount: 100, // 100XRP has been obtainedtransactionHash: '6FBE1C1215B8B3D0765D3CEC2FD48EE2BBC073DB8A960A92CA0485986CFE226C',seed: 'sEdTYR4byoAWLJUqFCGQsZsAX6ni9tc' // secret key}