Let's send money with XRP | Introduction to JavaScript
Create Script
-
Create a new file named
send_xrp.js
in your project directory. -
Paste the following code into
send_xrp.js
.- In
your_wallet_seed_here
, enter the secret key of the source address of the test net. - In
recipient_address_here
, enter the destination address of the testnet.
- In
Run Script
-
Run the script by executing the following command on the command line.
If successful, you will see the following in the console.
-
Search for the displayed hash value
1E33DACD3868BE78F67B89D4A68914E139CBAB17078A15BE2210FBA2D952F30D
in explorer on the testnet search.Then…you will see
UNFUNDED PAYMENT
, which means that the transmission has failed.Actually, you can check the result based on the value of the
TransactionResult
field displayed in the console! You should seeTransactionResult: 'tecUNFUNDED_PAYMENT'
in above.The address to which you sent this transaction has been issued 100 XRP by the Faucet tool, but the actual available balance is the amount minus 10 XRP which is used as a reserve(about 90 XRP). Also, please keep in mind that even a 90XRP transfer can fail because a fee must be paid at the time of transaction. Thus transactions are strictly verified.
-
Next, change the source of
send_xrp.js
toconst amount = '50';
and then try running thenode send_xrp.js
command.This time, the response is
TransactionResult: 'tesSUCCESS'
, confirming that the money transfer was successful.
Conclusion
We hope you have found that you can easily transfer XRP by using xrpl.js
, the client library.
Basically, the method of sending a transaction is the same as the others, and a trust line can be implemented by changing TransactionType: 'Payment'
to a different TransactionType
, which is TrustSet
.
As such, the way how public blockchain can be used by ordinary web developers and beginners is one of the strengths of the XRPL ecosystem.