Launch with a first buy and a burn
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 launch-with-burn.mjs, exactly as our tests run it on testnet. Point it at testnet with MM_API, or leave it for mainnet.
// Launch a token with a first buy in the same transaction (nobody can buy// before you), burn part of that buy at launch, and send the creator royalty to// buy back and burn the token for ever.// PRIVATE_KEY=0x… node launch-with-burn.mjsimport { JsonRpcProvider, Wallet } from 'ethers';
const API = process.env.MM_API ?? 'https://marketmayhem.co/api/v1';const DEAD = '0x000000000000000000000000000000000000dEaD';
const settings = await (await fetch(`${API}/settings`)).json();const rpc = settings.chainId === 56 ? 'https://bsc-dataseed.bnbchain.org' : 'https://bsc-testnet-rpc.publicnode.com';const wallet = new Wallet(process.env.PRIVATE_KEY, new JsonRpcProvider(rpc, settings.chainId));
const res = await fetch(`${API}/build/launch`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ wallet: wallet.address, name: process.env.NAME ?? 'Moth', symbol: process.env.SYMBOL ?? 'MOTH', marketCapUsd: process.env.MARKET_CAP_USD ?? '5000', firstBuy: process.env.FIRST_BUY ?? '0.01', // in BNB firstBuyTo: [{ wallet: DEAD, pct: 60 }, { wallet: wallet.address, pct: 40 }], // 60% of the buy burned burnPct: 100, // the royalty buys back and burns image: process.env.IMAGE ?? 'https://marketmayhem.co/icon-512.png', description: 'Moths go to the light.', }),});const launch = await res.json();if (!res.ok) throw new Error(`${launch.error.code}: ${launch.error.message} ${launch.error.fix ?? ''}`);
console.log(launch.explain);console.log(`the token will be ${launch.token}`); // known before you sendconst sent = await wallet.sendTransaction({ to: launch.tx.to, data: launch.tx.data, value: BigInt(launch.tx.value), gasLimit: BigInt(launch.tx.gas) });const receipt = await sent.wait();if (receipt.status !== 1) throw new Error(`reverted: ${sent.hash}`);console.log(`launched: https://marketmayhem.co/t/${launch.token}`);console.log('RESULT', JSON.stringify({ token: launch.token, hash: sent.hash }));