Sending Unowned Currencies (Tokens) | JavaScript XRPL Development Level 3
Next, we will explain the process of sending unowned currencies (tokens) as an additional topic to cross-currency payments.
We will continue to handle the issuer A’s A.USD.
Prerequisites
Daniel
does not hold A.USD
but needs to pay Alice
in A.USD
.
The amount of A.USD
to send to Alice
should be about 5 XRP
.
In cross-currency payments between different currencies, liquidity is always required, and the following process is necessary.
Bob
creates an offer to exchangeA.USD
forXRP
, providing liquidity.- Daniel, who does not hold
A.USD
, will pay Alice using up to5 XRP
(assuming there is liquidity; otherwise, the payment will fail). - The process is successful if
Alice
receives100 A.USD
.
1. Create Offer from Bob (Provide Liquidity)
For cross-currency payments to occur, liquidity must exist.
Bob creates an offer to exchange his A.USD
for XRP
, providing liquidity.
-
Modify the previously created createOffers.js as follows (comment out unnecessary parts).
-
Run the script.
This completes the creation of Bob’s offer to sell his
A.USD
and buyXRP
.
2. Daniel Sends A.USD
to Alice
Daniel will send A.USD
to Alice.
Daniel wants to pay using XRP
, but he does not want to spend more than necessary, so he wants to set a maximum limit for the payment.
In such cases, you can specify the amount using sendMax
. In XRPL, the sendMax
field allows you to set a maximum amount for the payment. (A minimum can also be specified.)
The route is quite simple; here, it will be Daniel → Bob → Alice
. Of course, if the token is highly liquid, the optimal route will be selected automatically.
-
Modify the previously created
crossCurrencyPayment.js
as follows (comment out unnecessary parts). -
Run the script.
If the following log is displayed, the transaction is successful.
Please check it using the Explorer for Testnet.
This completes the transfer of
A.USD
to Alice.To recap,
Daniel
sentA.USD
toAlice
, staying within the limit of5 XRP
. Bob had placed an order to exchange100 A.USD
for5 XRP
, so ultimately,Bob
received5 XRP
andAlice
received theA.USD
thatBob
held.
Summary
As demonstrated in this guide, with XRPL, you can send currency that you do not hold as long as there is liquidity. The fact that such functionality is provided natively is a strength of XRPL and the reason why XRPL is originally called a blockchain for payments.
Recently, powerful features like AMM have been incorporated, and it continues to evolve. However, I believe that understanding these basic concepts is essential before attempting to master more complex features. Please continue to work on mastering them.
The simple transfer mechanism itself may be difficult to visualize based solely on documentation, so I hope this knowledge will be helpful in your future development and projects.