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

v6

viem

v2

web3.js

v4

@solana/web3.js

v1

Installation

Using npm

npm install ethers @tokenkickstarter/sdk

Using yarn

yarn add ethers @tokenkickstarter/sdk

Basic 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

void
claim()

Claim purchased tokens after presale ends

void
refund()

Claim refund if presale failed

void
getContribution(address)

Get contribution amount for an address

uint256
getClaimable(address)

Get claimable token amount

uint256
presaleInfo()

Get presale details

PresaleInfo

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:

Continue Learning

Set up webhooks for server-side notifications or check rate limits.