How to Create an Offer | XRPL Development with JavaScript Level 2
Introduction
The XRPL (XRP Ledger) provides native Decentralized Exchange (DEX) functionality, allowing users to create offers (orders) to buy and sell assets. In this article, we will explain how to create an offer on XRPL.
Preparation
When sending tokens other than the native currency XRP
, you need to specify the currency code and issuer.
Tokens on XRPL always have an issuer, and preparing your own issuer each time is inefficient for learning purposes. Therefore, to improve efficiency, you can identify and use an existing issuer in advance.
An address that has already issued the currency code USD
exists on the testnet, so we will use this one.
Create the Script
-
Create a new file named
create_offer.js
in your project directory. -
Paste the following code into
create_offer.js
.Let’s create an offer to buy
200 USD
tokens for20 XRP
.- Set the asset you are offering in TakerGets and the asset you are receiving in TakerPays.
Run the Script
-
Run the following command in the command line to execute the script.
-
If successful, the console will display the following.
The offer creation was successful.
If this USD were a stablecoin, it is unlikely that someone would want to exchange 20 XRP (about $10 as of 2024/05/15) for 200 USD. However, this example demonstrates how easy it is to place orders on XRPL’s native DEX.