Everything with the SDK
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 sdk.mjs, exactly as our tests run it on testnet. Point it at testnet with MM_API, or leave it for mainnet.
// 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 }));