Watch every new launch
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 watch-launches.mjs, exactly as our tests run it on testnet. Point it at testnet with MM_API, or leave it for mainnet.
// Every new launch, the moment it is indexed, none missed. Polls with the// `next` cursor: pages never end part-way through a block.// node watch-launches.mjs (SECONDS=60 to stop after a minute)const API = process.env.MM_API ?? 'https://marketmayhem.co/api/v1';const stopAt = process.env.SECONDS ? Date.now() + Number(process.env.SECONDS) * 1000 : Infinity;
// Start from now: the newest launch's block.let { next } = await (await fetch(`${API}/launches?limit=1`)).json();let seen = 0;console.log(`watching from block ${next}`);
while (Date.now() < stopAt) { const page = await (await fetch(`${API}/launches?after=${next}`)).json(); for (const l of page.launches) { seen += 1; console.log(`new: $${l.symbol} ${l.token} by ${l.creator} https://marketmayhem.co/t/${l.token}`); } next = page.next; await new Promise((r) => setTimeout(r, 3000));}console.log('RESULT', JSON.stringify({ seen, next }));