Buy & Sell Tokens
How to trade tokens on the bonding curve using direct contract calls. All operations are denominated in lots (1 lot = 1,000 tokens).
Buying Tokens
Step 1: Get a Price Quote
const curve = new ethers.Contract(CURVE_ADDRESS, CURVE_ABI, provider);
const lotsToBy = 100; // 100 lots = 100,000 tokens
const [base, tax, total] = await curve.quote_buy_price(lotsToBuy);
console.log("Base cost:", ethers.utils.formatEther(base));
console.log("Tax:", ethers.utils.formatEther(tax));
console.log("Total (send this):", ethers.utils.formatEther(total));
Step 2: Execute Buy
const curveSigner = curve.connect(signer);
const tx = await curveSigner.buy(lotsToBuy, {
value: total // Must be EXACT — no more, no less
});
await tx.wait();
Exact Payment Required
The buy() function asserts msg.value == total. If you send even 1 wei more or less, the transaction reverts. Always use the exact value from quote_buy_price().
Selling Tokens
Step 1: Get Sell Quote
const lotsToSell = 50;
const [base, tax, proceeds] = await curve.quote_sell_price(lotsToSell);
console.log("You will receive:", ethers.utils.formatEther(proceeds));
Step 2: Approve & Sell
// The bonding curve burns tokens via burnFrom, which requires allowance
const token = new ethers.Contract(TOKEN_ADDRESS, ERC20_ABI, signer);
const amount = lotsToSell * 1000 * 10**9; // lots × LOT_SIZE
await (await token.approve(CURVE_ADDRESS, amount)).wait();
await (await curveSigner.sell(lotsToSell)).wait();
Deployer Cannot Sell
The deployer's tokens are locked. sell() will revert with "Deployer locked" if called by the deployer address.
Checking Your Balance
// Balance in lots
const lots = await curve.get_user_token_balance(walletAddress);
// Balance in raw tokens
const raw = await token.balanceOf(walletAddress);
// Max lots per wallet during bonding phase: 36,000