Add Assets to an AMM in JavaScript
This guide uses a sample web page to deposit assets into an existing automated market maker (AMM) and receive LP tokens in return. It also shows how to vote on the AMM's trading fee, check what your LP tokens are worth and redeem them for assets.
- Section
- Tutorials
What you need
First follow the Create an AMM guide, because you use that AMM here. Download the Quickstart Samples archive. Without it you cannot try the examples. Open the sample page in a browser, choose Testnet or Devnet and get test accounts, from seeds you already have or as new accounts.
Deposit assets
Enter the two currency codes of the AMM and the issuer of the second asset, then check the AMM. Look up your balances, enter an amount for one asset or for both, and add them to the AMM. You can deposit either asset on its own, but depositing only one reduces the amount of LP tokens you receive. Behind the page, the code builds an AMMDeposit transaction as a single or double-asset deposit.
Vote on the fee
Enter a value in the Trading Fee field and vote. The fee is in units of 1/100,000, so a value of 1 equals 0.001%. The maximum value is 1000, which means a 1% fee. Trading fees apply to any transaction that interacts with the AMM. The vote is sent as an AMMVote transaction.
Value and redeem
No dedicated method calculates what your LP tokens can be redeemed for, but the sum is simple. The code works out what percentage of the LP tokens in circulation you own, then applies that percentage to the total assets in the AMM. To redeem, enter a number of LP tokens. The page then sends an AMMWithdraw transaction.
Good to know
LP tokens you receive for a deposit count as tokens issued by the AMM's own account. The code uses that account to find the LP token among your wallet balances.
Source: xrpl.org. Read 6 December 2026.
Zerpedia states what the source says, in plain words, and gives no opinion. How Zerpedia is made