Skip to main content

Launch for your users

Your launchpad can launch coins for your users in two ways. This page shows both, with complete code.

You need a launchpad first. Getting started registers one.

Two ways to launch​

Your users' wallets launchYour server launches for them
Who signs the launchThe user's wallet, inside your appYour server's wallet
Who pays the gas and a first buyThe userYou
Who earns the creator's feesThe user, unless the launch names othersThe wallet you name as feeRecipient: the user
Who earns your launchpad's cutYour payeesYour payees
What you runNothing, or one route that approves launchesA script or a service with a funded wallet
Use it whenYour users have walletsYour users have no wallet connected, or pay no gas

A first buy is a buy the launcher makes inside the launch transaction. The option is devBuy.

Who earns which fee​

Every trade of a coin pays one fee, in the coin's quote token. It splits the same way in both setups:

  1. Bankr's cut comes first. Half of it goes to the coin's holders.
  2. Your launchpad's payees take their shares of what is left. You set them when you set up your launchpad.
  3. The creator side is the rest. It pays the coin's fee recipients, after any auto-LP share and holder share the launch carries.

The fee recipient is the launcher by default. A launch can name another wallet with feeRecipient, or up to 10 with feeRecipients. Fees has the numbers and shows how each party claims.

Your users' wallets launch​

The user's wallet sends one transaction. It creates the coin, and the user is its launcher and its fee recipient.

On an open launchpad, one with no signer, this needs no server at all:

// launch.ts, in your web app
import {
createLaunchClient,
isLaunchSdkError,
type LaunchClient,
} from "@bankr/launch-sdk";
import type { Address, WalletClient } from "viem";

const LAUNCHPAD_ID = 7n; // your launchpad's id

/** `walletClient` is your user's connected wallet: wagmi's `useWalletClient()`, or viem's `createWalletClient`. */
export function makeClient(walletClient: WalletClient): LaunchClient<"base"> {
return createLaunchClient({
chain: "base",
walletClient,
api: {}, // lists each launch in Bankr's launch index sooner
});
}

export async function launchCoin(
client: LaunchClient<"base">,
user: Address,
form: { name: string; symbol: string; metadataUri: string },
) {
try {
const result = await client.launch({
...form,
launcher: user, // the connected wallet's account
launchpadId: LAUNCHPAD_ID,
});
return { token: result.token, txHash: result.txHash };
} catch (err) {
if (!isLaunchSdkError(err)) throw err; // a wallet rejection or an RPC error from viem
return { error: `${err.code}: ${err.detail ?? err.message}` };
}
}

client.launch plans the launch, simulates it, asks the wallet to send it and reads the receipt. It returns the token's address, the pool, the fee recipients and the transaction hash.

With api: {}, client.launch returns only once the launch has 5 confirmations and Bankr's index has registered it, or after 2 minutes at most. Show your user the transaction as sent in the meantime, or leave api out to return as soon as the launch is mined.

@bankr/launch-sdk is safe to bundle for a browser. It holds no key.

Approve each launch on your server​

An open launchpad takes any launcher. To decide who may launch, give your launchpad a signer: a key you hold on your server. The contracts then accept only the launches that key has approved. An approval covers every term of one launch, is valid for 10 minutes and works once.

  1. The browser plans the launch and posts its exact terms to your server.
  2. Your server checks the request against your rules, then signs the terms with the signer key.
  3. The user's wallet sends the launch. The contracts check the signature.

Name the signer on your launchpad once, from the operator wallet. launchpads and send are the ones from Set up a launchpad:

await send(
await launchpads.setSigner(
launchpadId,
"0x2222222222222222222222222222222222222222", // your signer key's address
),
);

Then add the route. createAuthorizeHandler builds a function that takes a Request and returns a Response. It fits Next.js route handlers, Hono, Bun and any other server that speaks the Fetch API.

// app/api/launch/authorize/route.ts
import { parseUnits } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import {
CHAINS,
createAuthorizeHandler,
percentToPips,
} from "@bankr/launch-sdk/server";

// The most a first buy may spend, per quote token, in that token's own units.
// Decimals differ by token and by chain, so one number is never a cap for every quote token.
const { WETH, USDC } = CHAINS.base.quotes;
const MAX_FIRST_BUY: Record<string, bigint> = {
[WETH.address]: parseUnits("0.1", WETH.decimals),
[USDC.address]: parseUnits("250", USDC.decimals),
};

export const POST = createAuthorizeHandler({
account: privateKeyToAccount(process.env.PAD_SIGNER_KEY as `0x${string}`),
chain: "base",
launchpadId: BigInt(process.env.LAUNCHPAD_ID ?? ""),
// Required. Check your user and your rules before the key signs. Throw to refuse.
authorize(req, launch) {
if (!req.headers.get("cookie")?.includes("session=")) {
throw new Response(JSON.stringify({ error: "Sign in to launch." }), {
status: 401,
});
}
// A first buy paid in ETH counts in WETH's units. A quote token with no cap here takes no first buy.
const firstBuy = launch.nativeDevBuy + launch.params.devBuyAmountIn;
const cap = MAX_FIRST_BUY[launch.params.quote.toLowerCase()];
if (firstBuy > 0n && (cap === undefined || firstBuy > cap)) {
throw new Response(
JSON.stringify({
error: "That first buy is over this launchpad's cap.",
}),
{ status: 403 },
);
}
if (launch.params.econ.buy.steadyPips !== percentToPips("1")) {
throw new Response(
JSON.stringify({ error: "Launches here trade at 1%." }),
{ status: 403 },
);
}
},
onError: (err) => console.error("launch authorization failed", err),
});

In the browser, add one option to the client:

// launch-approved.ts, in your web app
import { createLaunchClient, remoteAuthorizer } from "@bankr/launch-sdk";
import type { WalletClient } from "viem";

export function makeApprovedClient(walletClient: WalletClient) {
return createLaunchClient({
chain: "base",
walletClient,
authorizer: remoteAuthorizer("/api/launch/authorize"), // your route
api: {},
});
}

client.launch now asks your route to approve each launch before the wallet sends it. remoteAuthorizer(url, init?) takes the same init as fetch, for headers or credentials.

What the handler does for you:

  • It accepts only your launchpad. A request for another chain, registry or launchpad is refused with a 400.
  • It recomputes the terms. The hash it signs comes from the posted launch itself, never from a value the browser claims.
  • It has no default allow. authorize is required. A thrown Response is returned as it is. Anything else you throw becomes a 403.
  • It limits the request. POST only, a JSON body of at most 16 KiB.

launch in authorize is the whole request: launch.launcher, and launch.params, every term the launch names. Your launchpad's ranges and switches already bound every launch on-chain. Use authorize for the rules a range cannot say, such as who may launch and how often.

  • Sign in and rate-limit your users here. Without a check, anyone who finds the route can launch on your launchpad.
  • Keep the key on the server. The helpers in @bankr/launch-sdk/server refuse to run in a browser. In production, use a KMS- or HSM-backed account: account is any viem account with an address and signTypedData.
  • The signer is a plain key. Its address must have no code on the chain.

Your server launches for them​

Your server's wallet sends the launch and pays the gas. The launch names your user as the fee recipient, so the creator's fees are the user's from the first trade.

// launch-for-user.ts, on your server: `bun launch-for-user.ts`
import {
createPublicClient,
createWalletClient,
http,
type Address,
} from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
import { createLaunchClient, percentToBps } from "@bankr/launch-sdk";

const transport = http(process.env.BASE_RPC_URL);
const server = privateKeyToAccount(process.env.SERVER_KEY as `0x${string}`);
const client = createLaunchClient({
chain: "base",
publicClient: createPublicClient({ chain: base, transport }),
walletClient: createWalletClient({ account: server, chain: base, transport }),
api: {},
});

export async function launchFor(
user: Address,
coin: { name: string; symbol: string; metadataUri: string },
) {
const result = await client.launch({
...coin,
launcher: server.address, // your server signs and pays the gas
launchpadId: BigInt(process.env.LAUNCHPAD_ID ?? ""),
feeRecipient: user, // the creator's fees go to your user
vesting: { bps: percentToBps("15"), recipient: user }, // and so does the creator's vested supply
metadataAdmin: user, // your user may update the coin's image and description
});
return result.token;
}

console.log(
await launchFor("0x3333333333333333333333333333333333333333", {
name: "Acme Coin",
symbol: "ACME",
metadataUri: "ipfs://your-metadata-cid",
}),
);

Three things to name, because each defaults to the launcher, which is your server:

OptionDefaultName your user to
feeRecipientThe launcherPay them the creator's fees.
vesting.recipientThe launcherGive them the creator's vested supply.
metadataAdminNobodyLet them replace the coin's metadata link. Leave it out to fix the link.

A first buy (devBuy) is paid by the launcher and its tokens go to the launcher. Leave it out when your server launches.

If your launchpad has a signer, your server approves its own launches. Pass padAuthorizer({ account }) from @bankr/launch-sdk/server as the client's authorizer, with the signer key's account.

Safes, smart accounts and your own sender​

client.launch needs a wallet client. For any other sender, build the transaction and send it yourself. client and launchpadId are the ones from the samples above.

const plan = await client.plan({
name: "Acme Coin",
symbol: "ACME",
metadataUri: "ipfs://your-metadata-cid",
launcher: "0x4444444444444444444444444444444444444444", // the Safe or smart account that will send it
launchpadId,
deadlineSeconds: 3_600, // leave time to collect signatures
});
const tx = client.buildLaunchTx(plan); // { to, data, value, gas }: send it from `launcher`
console.log(tx.to, plan.predictedToken);

After it lands, client.parseLaunchReceipt(receipt) reads the launch.

A plan goes stale. Its start price follows the quote token's price, any approval by your signer expires, and it is pinned to the terms in force when it was planned. If the launch is sent late and reverts, plan again.

Metadata​

A launch carries metadataUri: a link to the token's metadata JSON, at most 2,048 bytes. Your app hosts or pins that JSON before the launch, for example on IPFS.

The link is fixed at launch unless the launch names a metadataAdmin. Metadata covers it.

Show errors​

Every refusal the SDK makes is a LaunchSdkError with a stable code. err.detail is a sentence you can show.

CodeShow your user
LAUNCHPAD_PAUSEDLaunches are paused on this launchpad.
FEE_OUT_OF_BOUNDSThe fee is outside the launchpad's range. err.detail states the range.
OUTSIDE_LAUNCHPAD_RANGEAnother term is outside the launchpad's range. err.detail names it.
NOT_ALLOWED_BY_LAUNCHPADThe launch uses a feature the launchpad switched off.
INVALID_PARAMSA field is wrong. err.detail says which.
API_ERRORYour authorize route refused or failed.
AUTHORIZATION_INVALIDThe approval expired before the launch landed. Launch again.
SIMULATION_REVERTEDThe launch would revert. launchRevertName(err.cause) names the reason.

Errors lists every code.

See your launches​

Bankr indexes every launch on every launchpad. You run no indexer.

const { launches } = await client.index.launches({
launchpad: launchpadId,
visibility: "all",
});
for (const l of launches) console.log(l.symbol, l.tokenAddress, l.launcher);

With api: {} on the client, client.launch registers each launch with the index once it has 5 confirmations, so it shows sooner. Reading launches has every filter.