Quote a buy (JavaScript)
Tested on BSC testnet before every release
This is an example. Every value in it (names, amounts, addresses) is there to show you how; change any of them to suit you. It’s quote.mjs, exactly as our tests run it on testnet. Point it at testnet with MM_API, or leave it for mainnet.
// What a buy gets right now. Reads only; no wallet needed.// TOKEN=0x… node quote.mjsconst API = process.env.MM_API ?? 'https://marketmayhem.co/api/v1';const token = process.env.TOKEN;
const url = `${API}/quote?token=${token}&side=buy&amount=0.01`;const res = await fetch(url);const quote = await res.json();if (!res.ok) throw new Error(`${quote.error.code}: ${quote.error.message} ${quote.error.fix ?? ''}`);
console.log(`0.01 ${quote.pay.symbol} buys about ${quote.receive.amount} ${quote.receive.symbol}`);console.log(`at least ${quote.limit.amount} after ${quote.slippageBps / 100}% slippage; price impact ${quote.priceImpactPct}%`);console.log('RESULT', JSON.stringify({ receive: quote.receive.amount }));