Send and receive tokens (beyond XRP) with React.js
Transfer value beyond XRP using the XRPL’s trustline feature.
Receive tokens beyond XRP by creating a trust line
On the XRPL, you can create tokens to represent valuable things beyond XRP. For example, someone could create a stablecoin token representing a fiat currency on-ledger.
On other chains you are allowed to send any token to anyone. Metaphorically, that’s like saying anyone can put any coin into your wallet, even if you would never use it.
Instead, on the XRPL, you have to explicitly indicate that you are willing to accept a token. You do this by establishing a “trust line” to a specific account for a particular token up to a max amount. You need to specify the particular account you trust because token names are not unique. A digital representation of a dollar is more credible if it was created by a bank than if a random stranger created it.
If you have a trust line established, other people with that token can send it to you, and vice versa. So, this lesson will show you how to establish a trust line and send tokens afterward.
Seeing this in action
- Open the sandbox below which will demonstrate how trust lines work.
- Wait for the test accounts to finish being created.
- Copy the address of the source wallet.
- Paste that address into the first blank field of the destination wallet.
- Set a limit for the maximum amount of currency you want to receive from the source wallet. (We set the currency to USD in this example, but you can change it to whatever you want).
– This indicates the destination wallet is willing to receive tokens with the specified name (USD by default) from the source wallet.
- Click Send to create the trust line.
– Behind the scenes this sends a “TrustSet” transaction with the information you provided.
- Now, send some tokens from the source wallet to the destination wallet.
– Note: If you try to send more than the maximum you set in your trust line, it will fail!