The SDK
TypeScript · JavaScript · Node 20+ · npm i @marketmayhem/sdk
sdk.mjs
The SDK is the API with the glue done for you. Your key signs in your own process; the API builds and simulates every transaction; the SDK sends the one-time approvals when they’re needed, retries rate limits and brief outages, and waits until each trade is indexed.
import { MarketMayhem } from '@marketmayhem/sdk';
const mm = MarketMayhem.fromPrivateKey(process.env.PRIVATE_KEY);await mm.buy('0xTOKEN', { spend: '0.05' });A complete example
Section titled “A complete example”A buy, selling half, a launch that burns part of its first buy, and your referral link. It runs on BSC testnet before every release.
// The same jobs with the SDK: approvals, retries and waiting are handled for you.// npm i @marketmayhem/sdk// PRIVATE_KEY=0x… TOKEN=0x… node sdk.mjsimport { MarketMayhem } from '@marketmayhem/sdk';
const mm = MarketMayhem.fromPrivateKey(process.env.PRIVATE_KEY, { api: process.env.MM_API });const token = process.env.TOKEN;
// Buy with 0.0005 BNB. Waits until the trade is indexed.const bought = await mm.buy(token, { spend: '0.0005' });console.log(bought.explain, '→', bought.status, bought.hash);
// Sell half of what the wallet holds. A first sale's one-time approvals are sent for you.const sold = await mm.sell(token, { percent: 50 });console.log(sold.explain, '→', sold.status, sold.hash);
// Launch a token, burning 60% of its first buy.const launched = await mm.launch({ name: 'SDK Example', symbol: 'SDKX', marketCapUsd: '15', firstBuy: '0.0003', image: 'https://marketmayhem.co/icon-512.png', // the logo: every launch needs one firstBuyTo: [{ wallet: '0x000000000000000000000000000000000000dEaD', pct: 60 }, { wallet: mm.address, pct: 40 }],});console.log('launched', launched.url);
// Your referral link.console.log('your link:', await mm.referralLink());
console.log('RESULT', JSON.stringify({ bought: bought.status, sold: sold.status, token: launched.token }));MarketMayhem.fromPrivateKey(key, options?) | Sign with a key. It never leaves your process. |
MarketMayhem.fromWalletClient(walletClient, options?) | Sign with any viem wallet: a browser wallet, a hardware wallet, a KMS signer. |
MarketMayhem.readOnly(options?) | Quotes, tokens, launches and referrals, with no wallet. |
| Option | Default | Meaning |
|---|---|---|
api | https://marketmayhem.co/api/v1 | The API. Its /settings says which chain it’s on. |
rpcUrl | a public BSC node | Where transactions are sent. |
referrer | the API’s rule | A registered referrer paid the referral cut on your trades; null for nobody. |
apiKey | — | Your API key: your wallet becomes the default referrer. |
Methods
Section titled “Methods”| Method | Returns |
|---|---|
buy(token, { spend, slippageBps? }) | { hash, status, explain, approvals } |
sell(token, { amount } or { percent }, slippageBps?) | the same |
launch({ name, symbol, marketCapUsd, … }) | { token, hash, url, explain }. Every launch option is accepted. |
previewBuy, previewSell, previewLaunch (same arguments) | The transaction built and simulated for this wallet, with its explain. Sends nothing. |
quote(token, 'buy' | 'sell', amount) | the live quote |
token(address), launches({ after?, limit? }) | reads |
watchLaunches({ everyMs?, signal? }) | an async iterator of every new launch |
tx(hash), waitForIndexed(hash) | where a transaction is |
referrals(address?), referralLink({ address?, path? }) | earnings and links |
settings() | network, contracts, fees, pairs, limits |
The SDK’s types are generated from the API’s own description (openapi.json), so they match what the API sends.