API Reference
Web3 Integration
Interact directly with TokenKickstarter smart contracts using popular Web3 libraries like ethers.js, viem, or web3.js.
Supported Libraries
ethers.js
v6viem
v2web3.js
v4@solana/web3.js
v1Installation
Using npm
npm install ethers @tokenkickstarter/sdkUsing yarn
yarn add ethers @tokenkickstarter/sdkBasic Example
Contributing to a Presale
import { ethers } from 'ethers';
import PresaleABI from './abis/Presale.json';
// Connect to provider
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
// Initialize contract
const presaleAddress = '0x1234...5678';
const presale = new ethers.Contract(
presaleAddress,
PresaleABI,
signer
);
// Contribute to presale
const amount = ethers.parseEther('0.1');
const tx = await presale.contribute({ value: amount });
await tx.wait();
console.log('Contribution successful!');Contract Methods
contribute()Contribute native currency to the presale
claim()Claim purchased tokens after presale ends
refund()Claim refund if presale failed
getContribution(address)Get contribution amount for an address
getClaimable(address)Get claimable token amount
presaleInfo()Get presale details
Event Listening
Subscribe to contract events for real-time updates:
// Listen for contribution events
presale.on('Contribution', (contributor, amount, tokens) => {
console.log(`New contribution:`);
console.log(` From: ${contributor}`);
console.log(` Amount: ${ethers.formatEther(amount)} ETH`);
console.log(` Tokens: ${ethers.formatEther(tokens)}`);
});
// Listen for presale finalization
presale.on('PresaleFinalized', (success, liquidityAdded) => {
console.log(`Presale finalized: ${success ? 'Success' : 'Failed'}`);
});Contract ABIs
Download contract ABIs for integration: