Trade Entity

You can use the Trade Entity to safely calculate all the data required to interact with the Router. If you're using a custom router smart contract, this guide may not apply.

Let's consider trading 1 WR5 for as much TOKEN1 as possible:

import {
    ChainId,
    Token,
    WR5,
    CurrencyAmount,
    TradeType,
    Trade,
    Route,
     } from "r5-defi-engine"
     
const TOKEN1 = new Token(ChainId.R5, '0x123...', 18)

const route = new Route([pair], WR5[TOKEN1.chainId], TOKEN1)

const amountIn = '1000000000000000000' // 1 WR5

const trade = new Trade(route, CurrencyAmount.fromRawAmount(WR5[TOKEN1.chainId], amountIn), TradeType.EXACT_INPUT)

Now that you have constructed the trade entity, there are a few more steps to go through before sending the transaction.

The first step is to select the appropriate router function. In this case:

Now, we can construct all the parameters so we can send the transaction to be processed:

Last updated