Skip to main content
All examples use viem. Replace tokenAddress with the bonding curve address of the token you are integrating with.

Get token information

import { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';

const client = createPublicClient({
  chain: mainnet,
  transport: http(),
});

const tokenDetails = await client.readContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'getBondingCurveSettings',
});

Get current price

const price = await client.readContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'getPriceForBuy',
  args: [parseEther('0.1')],
});

Buy tokens

import { createWalletClient, custom } from 'viem';

const walletClient = createWalletClient({
  transport: custom(window.ethereum),
});

const hash = await walletClient.writeContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'buy',
  value: parseEther('1'),
});

Sell tokens

const hash = await walletClient.writeContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'sell',
  args: [parseEther('1000')],
});

Check phase

const currentPhase = await client.readContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'currentPhase',
});
// 0 = Pre-Bond, 1 = Bonding, 2 = Finalized