Skip to main content

πŸ” Monad Meta Aggregator Swap API Guide

This guide shows how to fetch a swap quote using the monad meta aggregator API with viem in typescript.


🌐 endpoint​

GET https://alpha.clober.io/api/quote

πŸ“₯ query parameters​

nametypedescription
inputTokenAddressstringaddress of the input token (e.g. native ETH is 0x0000000000000000000000000000000000000000)
outputTokenAddressstringaddress of the token you want to receive
amountInstringamount of input token in wei
slippageLimitPercentstringslippage limit in percent (e.g. "1" for 1%)
userAddressstring (optinal)user's wallet address (if userAddress is not provided, the API will not build a transaction)

πŸ“¦ example request​

GET https://alpha.clober.io/api/quote?inputTokenAddress=0x0000000000000000000000000000000000000000&outputTokenAddress=0xf817257fed379853cDe0fa4F97AB987181B1E5Ea&amountIn=1000000000000000000&slippageLimitPercent=1&userAddress=0x5F79EE8f8fA862E98201120d83c4eC39D9468D49

πŸ§ͺ using viem + typescript​

import axios from 'axios'
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { monadTestnet } from 'viem/chains'

const account = privateKeyToAccount('0xYOUR_PRIVATE_KEY')
const client = createWalletClient({
account,
chain: monadTestnet,
transport: http(),
})

async function fetchAndExecuteQuote() {
const inputToken = '0x0000000000000000000000000000000000000000' // native ETH
const outputToken = '0xf817257fed379853cDe0fa4f97AB987181B1E5Ea'
const amountIn = '1000000000000000000' // 1 ETH in wei
const slippage = '1'
const userAddress = account.address

try {
const { data } = await axios.get('https://alpha.clober.io/api/quote', {
params: {
inputTokenAddress: inputToken,
outputTokenAddress: outputToken,
amountIn,
slippageLimitPercent: slippage,
userAddress,
},
}) as {
data: {
bestQuote: {
aggregator: string
amountOut: string
transaction: {
to: `0x${string}`
data: `0x${string}`
value: string
gas: string
gasPrice: string
}
}
}
}

const best = data.bestQuote
console.log('βœ… best aggregator:', best.aggregator)
console.log('πŸ” expected amountOut:', best.amountOut)

const tx = best.transaction

const hash = await client.sendTransaction({
to: tx.to as `0x${string}`,
data: tx.data as `0x${string}`,
value: BigInt(tx.value),
gas: BigInt(tx.gas),
gasPrice: BigInt(tx.gasPrice),
})

console.log('πŸš€ sent tx hash:', hash)
} catch (err) {
console.error('❌ error while quoting or sending tx:', err)
}
}

fetchAndExecuteQuote()

πŸ“˜ sample response​

this is a sample response from the monad meta aggregator quote api. it includes the best available quote and a list of all quotes from supported aggregators.

{
"bestQuote": {
"amountOut": "1528866",
"aggregator": "Monorail",
"transaction": {
"from": "0x5F79EE8f8fA862E98201120d83c4eC39D9468D49",
"to": "0xfD845859628946B317A78A9250DA251114FbD846",
"data": "0xb69cbf9f0000...", // encoded calldata
"value": "1000000000000000000",
"gas": "940662",
"gasPrice": "52000000000"
},
"executionMilliseconds": 330.06097
},
"allQuotes": [
{
"amountOut": "1528866",
"aggregator": "Monorail",
"transaction": {
"from": "0x5F79EE8f8fA862E98201120d83c4eC39D9468D49",
"to": "0xfD845859628946B317A78A9250DA251114FbD846",
"data": "0xb69cbf9f0000...",
"value": "1000000000000000000",
"gas": "940662",
"gasPrice": "52000000000"
},
"executionMilliseconds": 330.06097
},
{
"amountOut": "1522248",
"aggregator": "OpenOcean",
"transaction": {
"from": "...",
"to": "...",
"data": "...",
"value": "1000000000000000000",
"gas": "872528",
"gasPrice": "52000000000"
},
"executionMilliseconds": 347.45342
},
{
"amountOut": "1521628",
"aggregator": "Clober",
"transaction": {
"from": "...",
"to": "...",
"data": "...",
"value": "1000000000000000000",
"gas": "693416",
"gasPrice": "52000000000"
},
"executionMilliseconds": 274.84042
}
]
}
  • amountOut: expected output token amount after the swap (in smallest unit, e.g. wei)
  • aggregator: name of the aggregator/router that provides the quote
  • transaction: full transaction object that can be submitted via viem.sendTransaction()
    • from: address that will initiate the transaction (usually user’s wallet address)
    • to: router contract address to be called
    • data: encoded calldata for executing the swap
    • value: amount of ETH to send along with the transaction (if input is native ETH)
    • gas: suggested gas limit for executing the swap
    • gasPrice: suggested gas price in wei
  • executionMilliseconds: time taken to compute this quote (used for diagnostics)