Cross-Currency Payment | XRPL Development in JavaScript - Level 3
This guide explains cross-currency payments by dealing with A.USD
issued by Issuer A and B.EUR
issued by Issuer B.
In the previous section, we confirmed that Alice can place an offer to sell A.USD
issued by Issuer A and buy B.EUR
issued by Issuer B, allowing Daniel to send A.USD
to Charlie (liquidity is available).
In this section, let’s actually send A.USD
from Daniel to Charlie!
Prerequisites
Alice has already placed an offer to sell A.USD
issued by Issuer A and buy B.EUR
issued by Issuer B, thereby providing liquidity.
Daniel needs to make a payment to Charlie, who wants to receive A.USD
. However, Daniel currently does not hold any A.USD
; he only has XRP and B.EUR
issued by Issuer B. Daniel is considering to exchange his B.EUR
for A.USD
.
After searching for someone willing to exchange B.EUR
for the desired amount of A.USD
, Daniel confirms that such a person exists. Now, he will proceed to send A.USD
to Charlie by exchanging his B.EUR
.
Creating the Script
-
Create a new file named
crossCurrencyPayment.js
in your project directory. -
Paste the following code into
crossCurrencyPayment.js
.
Running the Script
-
Execute the following command in the command line to run the script.
-
If you see logs like the following, the operation was successful.
At this point, verify the following using the Explorer:
- Alice’s balance of
A.USD
has decreased to900
, and her balance ofB.EUR
has increased to1,100
. - Charlie’s balance of
A.USD
has increased to1,100
. - Daniel’s balance of
B.EUR
has decreased to900
.
This demonstrates that the XRPL has a unique feature that allows for “simultaneous payment and swap (exchange)“.
- Alice’s balance of
Summary
Cross-currency payments are a unique feature of the XRPL, which has a native DEX, and it is one of its most representative functions.
In the XRPL, even if the currencies (tokens) are issued by different issuers, as long as there is liquidity, you can deliver the currency you want to pay in as the currency the recipient wants to receive.
In the next section, we will delve deeper into the topic of cross-currency payments.