Launch a token
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.mjs, exactly as our tests run it on testnet. Point it at testnet with MM_API, or leave it for mainnet.
// Launch a token: a name, a ticker and an opening market cap. That's all it needs.// PRIVATE_KEY=0x… node launch.mjsimport { JsonRpcProvider, Wallet } from 'ethers';
const API = process.env.MM_API ?? 'https://marketmayhem.co/api/v1';
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));
// 1. The API builds the launch for your wallet and simulates it.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', image: process.env.IMAGE ?? 'https://marketmayhem.co/icon-512.png', // the logo: every launch needs one }),});const launch = await res.json();if (!res.ok) throw new Error(`${launch.error.code}: ${launch.error.message} ${launch.error.fix ?? ''}`);console.log(launch.explain);
// 2. Your wallet signs and sends it. The key never leaves this process.const 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 }));