Skip to content

Trade on the bonding curve

Quote, buy, and sell a launch token with the Clank SDK while its curve is active.

Updated View as Markdown

Every Clank launch token starts on a bonding curve. Install the SDK to resolve the canonical curve, quote recipient-specific fees, apply slippage, and build the required approval and trade instructions.

pnpm add @clanktrade/sdk viem

This guide assumes your app has a Robinhood Chain publicClient, a connected walletClient, and the launch-token address.

Create the client

bonding-curve.tsts
import { createClankClient } from "@clanktrade/sdk";
import { parseEther, type Address } from "viem";

const launchToken = "0x..." as Address;
const [trader] = await walletClient.getAddresses();
if (!trader) throw new Error("Connect a wallet before trading");

const clank = await createClankClient({ publicClient, launchToken });
if (clank.venue !== "bonding-curve") {
  throw new Error("This launch has already graduated");
}

createClankClient verifies the launch through the canonical factory and reads the curve’s current state. States 1 and 2 are temporarily unavailable while graduation runs; state 3 creates a Uniswap V4 client instead.

State Value Trading behavior
Trading 0 The SDK trades through the bonding curve.
Ready 1 Trading pauses for graduation.
Swept 2 Trading remains paused.
PoolCreated 3 The SDK trades through Uniswap V4.
Rescued 4 No automatic trading venue is available.

Quote and build a buy

SDK buys are denominated in native ETH. For an ERC-20-paired curve, the SDK finds an ETH route and combines the swap and curve purchase into one trade.

bonding-curve.tsts
const buyQuote = await clank.quoteBuy({
  ethIn: parseEther("0.1"),
  trader,
  slippageBps: 100,
});

// Show these values before requesting wallet confirmation.
console.log({
  launchTokensOut: buyQuote.amountOut,
  minimumLaunchTokensOut: buyQuote.minimumAmountOut,
  pairTokenFee: buyQuote.fee,
  pairTokenRefund: buyQuote.refund,
  route: buyQuote.route.label,
});

const buyInstructions = await clank.buildBuy({
  quote: buyQuote,
  trader,
});

A direct native-ETH curve buy normally produces one instruction. An ERC-20-paired curve is routed through ClankRouterEth without requiring the trader to hold or approve the pair token.

Quote and build a sell

bonding-curve.tsts
const sellQuote = await clank.quoteSell({
  launchTokensIn: parseEther("1000"),
  trader,
  slippageBps: 100,
});

console.log({
  ethOut: sellQuote.amountOut,
  minimumEthOut: sellQuote.minimumAmountOut,
  pairTokenFee: sellQuote.fee,
  route: sellQuote.route.label,
});

const sellInstructions = await clank.buildSell({
  quote: sellQuote,
  trader,
});

The first sell may return an ERC-20 approval followed by the sell. Submit the instructions sequentially and wait for each successful receipt.

bonding-curve.tsts
for (const instruction of sellInstructions) {
  const hash = await walletClient.sendTransaction({
    account: trader,
    to: instruction.to,
    data: instruction.data,
    value: instruction.value ?? 0n,
  });
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
  if (receipt.status !== "success")
    throw new Error(`${instruction.label} reverted`);
}

Once the launch reaches state 3, use the same SDK interface as described in Trade after graduation.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close