@marketmayhem/sdk
v0.1.0
Published
Launch and trade tokens on BNB Chain in a few lines: approvals, simulation, retries and confirmation handled for you. Your key never leaves your process.
Maintainers
Readme
@marketmayhem/sdk
Launch and trade tokens on BNB Chain in a few lines. The API builds and simulates every transaction; this library signs it with your key, in your process, sends it, handles the one-time approvals, retries what can be retried, and waits until the trade is indexed.
npm i @marketmayhem/sdkimport { MarketMayhem } from '@marketmayhem/sdk';
const mm = MarketMayhem.fromPrivateKey(process.env.PRIVATE_KEY);
await mm.buy('0xTOKEN', { spend: '0.05' }); // BNB in, tokens out, waits until indexed
await mm.sell('0xTOKEN', { percent: 50 }); // approvals sent for you, the first time
const { token, url } = await mm.launch({ name: 'Moth', symbol: 'MOTH', marketCapUsd: '5000' });
for await (const launch of mm.watchLaunches()) console.log(launch.symbol, launch.token);Start
| | |
|---|---|
| MarketMayhem.fromPrivateKey(key, options?) | Sign with a key. It never leaves this process. |
| MarketMayhem.fromWalletClient(viemWalletClient, options?) | Sign with any viem wallet: browser, hardware, KMS. |
| MarketMayhem.readOnly(options?) | Quotes, tokens, launches, referrals. No wallet. |
Options: api (default https://marketmayhem.co/api/v1; its /settings says which chain), rpcUrl, referrer (a registered referrer paid the referral cut; null for nobody), apiKey.
Methods
| | Returns |
|---|---|
| buy(token, { spend, slippageBps? }) | { hash, status, explain, approvals } |
| sell(token, { amount } \| { percent }, …) | the same |
| launch({ name, symbol, marketCapUsd, firstBuy?, firstBuyTo?, burnPct?, royaltyTo?, image?, … }) | { token, hash, url, explain } |
| previewBuy(…) · previewSell(…) · previewLaunch(…) | the built, simulated transaction for this wallet. Sends nothing. |
| quote(token, side, amount) | the live quote |
| token(address) · launches({ after?, limit? }) · watchLaunches() | reads |
| tx(hash) · waitForIndexed(hash) | where a transaction is |
| referrals(address?) · referralLink({ path? }) | earnings and links |
| settings() | network, contracts, fees, pairs, limits |
Errors are MayhemError with the API's stable code, a message and a fix. Rate limits and brief unavailability are retried for you.
Types are generated from the API's own description (/api/v1/openapi.json), so they match what the API sends.
Docs and every error explained: marketmayhem.co/developers. MIT.
