Skip to main content
Before you start, make sure you have the network and contract addresses configured. See Addresses for details.

Quick Example: Read Token Info

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://evmrpc.kasplex.org");

const FACTORY = "0x5F65Df9DCf7d764CA9d319Baf89611d289546A81";
const FACTORY_ABI = [
  "function getTokenInfo(address token) view returns (tuple(uint256 tokenId, address creator, address pool, uint256 tokenReserves, uint256 kasReserves, uint256 createdAt, bool fulfilled, bool graduated, string metadataUri, uint256 paramVersion))",
  "function getCurrentPrice(address token) view returns (uint256)",
  "function getBondingCurveProgress(address token) view returns (uint256)",
];

const factory = new ethers.Contract(FACTORY, FACTORY_ABI, provider);

const TOKEN = "0x..."; // token address

const info = await factory.getTokenInfo(TOKEN);
const price = await factory.getCurrentPrice(TOKEN);
const progress = await factory.getBondingCurveProgress(TOKEN);

console.log("Token ID:", info.tokenId.toString());
console.log("Reserves:", ethers.formatEther(info.kasReserves), "KAS");
console.log("Price:", ethers.formatEther(price), "KAS");
console.log("Progress:", Number(progress) / 100, "%");
console.log("Graduated:", info.graduated);

Quick Example: Buy a Token

import { ethers } from "ethers";

const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

const FACTORY = "0x5F65Df9DCf7d764CA9d319Baf89611d289546A81";
const FACTORY_ABI = [
  "function buy(address token, uint256 minTokensOut) payable",
];

const factory = new ethers.Contract(FACTORY, FACTORY_ABI, signer);

const TOKEN = "0x...";
const kasAmount = ethers.parseEther("100"); // 100 KAS
const minTokensOut = 0n; // set proper slippage in production!

const tx = await factory.buy(TOKEN, minTokensOut, { value: kasAmount });
await tx.wait();
console.log("Buy tx:", tx.hash);
Always set a proper minTokensOut for slippage protection. Using 0 means no slippage protection and is only safe for testing.

Next Steps

Contract Overview

Understand the contract architecture

Buy & Sell

Learn how to trade tokens with slippage protection

Price Calculation

Understand the bonding curve math

ABI Reference

Full contract ABI reference