Skip to main content

Post a simple offer

Posting a simple offer is also referred to as an on-the-fly offer.


The tutorial assumes knowledge of JavaScript. Follow preparation to create a new tutorial folder.

Make sure to use a chain where Mangrove is live. You can find all all live addresses for Mangrove here


When running the tutorial be aware that some of the script calls the chain and it can therefore take a few seconds before the transaction is completed.

Start local node

Before proceeding, import the environment variables made as part of the preparation

source .env

Start Foundry's local node anvil to test things locally, with $RPC_URL coming from .env and pointing, for instance, to the Polygon Mumbai testnet.

anvil --fork-url $RPC_URL

Import and connect

Start up node in a new terminal and issue the following code which performs the following steps:

  1. The first thing needed is to import dotenv, this handles the .env file you added in the preparation.
  2. Then import both Mangrove and ethers from the Mangrove package. ethers will allow you to connect to a node and your wallet. Mangrove will allow you to connect to the Mangrove protocol.
  3. We connect to a local anvil node through LOCAL_URL. In order to connect to a real chain can replace LOCAL_URL with RPC_URL.
  4. The PRIVATE_KEY is needed in order to connect to your wallet.
  5. Once you have connected your wallet, you can connect to the Mangrove protocol using your wallet.

Check existing market

Next you need to connect to a market, in order to see the existing offers. This way you can figure out at what price you want to post your offer.

  1. Connect to the market using, with a base and a quote.
  2. Console log asks. This outputs table of the 50 best asks.
  3. Console log bidss. This outputs table of the 50 best bids.
(index)id │ maker │ volume │ price │

Post new offer

After having looked at the market you now know what the prices are and you can now post an offer at a better price, so that the offer will be on top of the book.

  1. First create a LiquidityProvider. This allows for posting new offers.
  2. Then you need to approve your account/wallet. To make sure that the transaction has been made, we do await tx.wait().
  3. Then you need to calculate how much provision is needed.
  4. You can then post an offer using, in this case wants: 100.5 and gives:100.4, which gives a price of 100.5/100.41.00099100.5/100.4\approx1.00099. And since you saw that the best price was 1.003\approx1.003 you know our offer will be at the top of the list.

Check market after new offer

We can then check if our offer has best been posted and is on the top of the list, as excepted.

  1. First log the offerId in order to makes sure, you know what offer is yours.
  2. Then log the asks for the market. You will then see that your offer is on top of the list.
> console.log(offerId);
> market.consoleAsks();
(index) │ id │ maker │ volume │ price │

Another way to check your offer is to go to testnet and look at the asks for DAI-USDC. Here you will be able to see your offer. This can only be done if you didn't use a local chain, but actually ran on a real chain.

The full script can be found on github.