Initiating a Swap
Create the client and get a quote
import { Mento, ChainId, deadlineFromMinutes } from '@mento-protocol/mento-sdk'
import { parseUnits } from 'viem'
const mento = await Mento.create(ChainId.CELO)
const USDm = '0x765DE816845861e75A25fCA122bb6898B8B1282a'
const CELO = '0x471EcE3750Da237f93B8E339c536989b8978a438'
const amountIn = parseUnits('100', 18)
const expectedOut = await mento.quotes.getAmountOut(USDm, CELO, amountIn)Build swap transaction (approval + swap)
const recipientAddress = '0x...' // address that receives the output tokens
const ownerAddress = '0x...' // address that holds tokenIn and signs the tx
const { approval, swap } = await mento.swap.buildSwapTransaction(
USDm,
CELO,
amountIn,
recipientAddress,
ownerAddress,
{
slippageTolerance: 0.5, // 0.5%
deadline: deadlineFromMinutes(5),
}
)Send with a viem wallet client
Summary
Last updated