In this section we will create your first payment transaction.
Creating the main structure of your script
Create a new file or edit index.ts
import { Client, Wallet } from"xrpl"constclient=newClient("wss://s.altnet.rippletest.net:51233")constmain=async () => {console.log("lets get started...");awaitclient.connect();// do something interesting hereawaitclient.disconnect();console.log("all done!");};main();
Running this to make sure everything works should console log a few things. If you are running this from your own node environment, don't forget to runnpm i xrpl to add it to your project.
Creating wallets
Let's add some wallet creation logic, we might as well create 2 wallets to have some fun.
The most important being TransactionResult: 'tesSUCCESS'
You can verify the transaction on the ledger, as it is readable by anyone at this point. Go to https://testnet.xrpl.org and paste the hash value (in my example case it would be CC8241E3C4B57ED9183D6031F4E370AC13B6CE9E2332BD7AF77C25BD6ADFA4F6. You should see it. Alternatively, check the wallet addresses as well (remember you are using the public key).
I prefer to check the balances programmatically to ensure everything has gone according to plan. Adding this code will do that:
Don't you find it limiting that the faucet only gives out 100 XRP? Why not create a function to print money to an address?
You have all the necessary building blocks:
You will need to create and fund new wallets with await client.fundWallet()
Remember, you can only transfer XRP up to the reserve, so a maximum of 90 XRP at a time for brand new accounts, unless you are brave enough to use a new transaction type.? (https://xrpl.org/docs/references/protocol/transactions/types/accountdelete/). However, be warned that you will have to wait a block or two before the account can be deleted.
The final function signature should look something like this `await printMoney({ destinationWallet, client })
I can't wait to see who writes this faster than ChatGPT !