Skip to content

POST /build/buy

An unsigned, simulated buy.

POST https://marketmayhem.co/api/v1/build/buy
FieldTypeRequiredMeaning
walletstringyesThe wallet that will sign and send
tokenstringyesA 0x address
amountstringyesexact “in”: what is spent; exact “out”: what is received
exactin · outin (default): amount is spent; out: amount is received
slippageBpsintegerBasis points; default 50 (0.5%)
referrerstring or nullPaid the referral cut inside the trade. Omit: your API key’s wallet; null: nobody.
FieldTypeRequiredMeaning
tokenobjectyesThe token traded
token.addressstringyesA 0x address
token.symbolstringyes
token.poolstringyesA 0x address
token.feeTierintegeryes
token.pairobjectyes
token.pair.addressstringyesThe pair currency’s contract (WBNB for BNB)
token.pair.decimalsintegeryesIts decimals
token.pair.symbolstringyesIts symbol, e.g. BNB
sidebuy · sellyesbuy: pay the pair currency, get the token; sell: the reverse
exactin · outyesin: pay is fixed; out: receive is fixed
slippageBpsintegeryesThe tolerance the limit is set from
payobjectyesWhat is spent
pay.amountstringyesA decimal amount in whole units, as a string: “0.05”
pay.weistringyesThe same amount in the smallest unit, an integer as a string
pay.symbolstringyesThe currency, e.g. BNB or the token’s ticker
receiveobjectyesWhat comes back, at the price now
receive.amountstringyesA decimal amount in whole units, as a string: “0.05”
receive.weistringyesThe same amount in the smallest unit, an integer as a string
receive.symbolstringyesThe currency, e.g. BNB or the token’s ticker
limitobjectyesThe floor (or ceiling) written into the trade: it reverts rather than fill worse
limit.amountstringyesA decimal amount in whole units, as a string: “0.05”
limit.weistringyesThe same amount in the smallest unit, an integer as a string
limit.kindminReceive · maxPayyes
siteFeeobjectyesThe site fee this trade pays
siteFee.amountstringyesA decimal amount in whole units, as a string: “0.05”
siteFee.weistringyesThe same amount in the smallest unit, an integer as a string
siteFee.symbolstringyesThe currency, e.g. BNB or the token’s ticker
siteFee.bpsintegeryesIts rate, in basis points
priceImpactPctnumberyesHow far this trade moves the price, in per cent
walletstringyesThe wallet it was built for
referrerobject or nullyesWho is paid the referral cut, and how much, or null
referrer.addressstringyesA 0x address
referrer.bpsintegeryesIts cut, in basis points of the trade
referrerNotestringWhy your key’s wallet was not used as referrer, when it was not
requiresobject[]yesOne-time steps to send and wait for first, in order. Empty when the wallet is ready.
requires[].stepstringyese.g. “approve-permit2”, “approve-router”, “approve-factory”
requires[].explainstringyes
requires[].txobjectyesAn unsigned transaction: sign it with the wallet and send it.
requires[].tx.chainIdintegeryes56 BSC mainnet, 97 BSC testnet
requires[].tx.tostringyesA 0x address
requires[].tx.datastringyesThe call data: send it exactly as it is
requires[].tx.valuestringyesBNB to send with it, in wei
requires[].tx.gasstringThe simulated gas plus a margin. Absent while a step in requires is still needed.
txobjectyesAn unsigned transaction: sign it with the wallet and send it.
tx.chainIdintegeryes56 BSC mainnet, 97 BSC testnet
tx.tostringyesA 0x address
tx.datastringyesThe call data: send it exactly as it is
tx.valuestringyesBNB to send with it, in wei
tx.gasstringThe simulated gas plus a margin. Absent while a step in requires is still needed.
simulationobjectyesThe simulation against the chain, from the wallet
simulation.ranbooleanyesWhether it was simulated: not while a step in requires is still needed
simulation.okbooleanyesIt would succeed if sent now
costobjectyesThe most the transaction can cost in gas, in BNB.
cost.gasPriceWeistringyesThe same amount in the smallest unit, an integer as a string
cost.maxWeistringyesThe same amount in the smallest unit, an integer as a string
cost.maxstringyesA decimal amount in whole units, as a string: “0.05”
expiresAtstringyesThe on-chain deadline
explainstringyesOne sentence to show before signing

Captured from BSC testnet, exactly as the API sent it (long calldata shortened).

{
"token": {
"address": "0x136bfd5f42250a568ce06ed1b145729b400e391c",
"symbol": "BRNT",
"pool": "0x0c779f6d50f5d27df85a84e8fc15e66202076e6d",
"feeTier": 10000,
"pair": {
"address": "0xae13d989dac2f0debff460ac112a837c89baa7cd",
"decimals": 18,
"symbol": "BNB"
}
},
"side": "buy",
"exact": "in",
"slippageBps": 50,
"pay": {
"amount": "0.0005",
"wei": "500000000000000",
"symbol": "BNB"
},
"receive": {
"amount": "1780786.99943692577655049",
"wei": "1780786999436925776550490",
"symbol": "BRNT"
},
"limit": {
"kind": "minReceive",
"amount": "1771883.064439741147667737",
"wei": "1771883064439741147667737"
},
"siteFee": {
"amount": "0.000005",
"wei": "5000000000000",
"symbol": "BNB",
"bps": 100
},
"priceImpactPct": 0.3781,
"wallet": "0x2bf842241129be12f3a0e4f21e25d2fd43d9e6da",
"referrer": null,
"requires": [],
"tx": {
"chainId": 97,
"to": "0xF265f08Ac720B4dCD6BA1928C5F13b0ff0bE207d",
"data": "0x3593564c0000000000000000000000000000000000000000000000000000000000000060…",
"value": "500000000000000",
"gas": "195949"
},
"simulation": {
"ran": true,
"ok": true
},
"cost": {
"gasPriceWei": "100000000",
"maxWei": "519594900000000",
"max": "0.0005195949"
},
"expiresAt": "2026-09-26T09:12:57.000Z",
"explain": "Buy about 1,780,790 BRNT for 0.0005 BNB (at least 1,771,880 BRNT). Site fee 0.000005 BNB."
}

Every error is { "error": { "code", "message", "fix"? } }. This endpoint can answer:

  • UNKNOWN_TOKEN: That address is not a token launched on Market Mayhem.
  • INVALID_AMOUNT: The amount is not a positive decimal number, or both/neither of amount and percent were sent.
  • INSUFFICIENT_BALANCE: The wallet cannot pay for this: the amount, or the gas, or both.
  • SIMULATION_FAILED: The transaction would revert on chain, so it was not returned. Nothing was sent.
  • SELF_REFERRAL: A wallet cannot be its own referrer.
  • REFERRER_NOT_REGISTERED: The referrer is neither a registered referrer nor a creator, so a trade cannot pay it.
  • POOL_TOO_THIN: The pool cannot fill that size in one trade.
  • CHAIN_UNREACHABLE: The chain could not be read just now. Nothing was sent.
  • RATE_LIMITED: Too many requests from this address in the last minute.