Quick Start
Setup Provider
Copy
import { ethers } from 'ethers'
const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()
Integration Examples
- JavaScript
- React
- Node.js
- Python
Copy
import { ethers } from 'ethers'
class InkyPumpClient {
private factory: ethers.Contract
private signer: ethers.Signer
constructor(signer: ethers.Signer) {
this.signer = signer
this.factory = new ethers.Contract(
TOKEN_FACTORY_ADDRESS,
FACTORY_ABI,
signer
)
}
async createToken(metadata: TokenMetadata, referral = "") {
const tx = await this.factory.createToken(
metadata,
referral,
{ value: ethers.utils.parseEther("0.001") }
)
const receipt = await tx.wait()
const tokenAddress = receipt.events[0].args.token
return tokenAddress
}
async buyTokens(
tokenAddress: string,
ethAmount: string,
referral = ""
) {
const quote = await this.factory.getQuoteBuy(
tokenAddress,
ethers.utils.parseEther(ethAmount)
)
if (quote.eq(0)) {
throw new Error("Token graduated or invalid")
}
const tx = await this.factory.buy(
tokenAddress,
referral,
{ value: ethers.utils.parseEther(ethAmount) }
)
return await tx.wait()
}
async sellTokens(
tokenAddress: string,
tokenAmount: string,
referral = ""
) {
const token = new ethers.Contract(
tokenAddress,
ERC20_ABI,
this.signer
)
const amount = ethers.utils.parseEther(tokenAmount)
const allowance = await token.allowance(
await this.signer.getAddress(),
TOKEN_FACTORY_ADDRESS
)
if (allowance.lt(amount)) {
const approveTx = await token.approve(
TOKEN_FACTORY_ADDRESS,
ethers.constants.MaxUint256
)
await approveTx.wait()
}
const tx = await this.factory.sell(
tokenAddress,
amount,
referral
)
return await tx.wait()
}
}
Copy
import { useState, useEffect } from 'react'
import { ethers } from 'ethers'
function useInkyPump() {
const [factory, setFactory] = useState<ethers.Contract | null>(null)
useEffect(() => {
async function setup() {
if (!window.ethereum) return
const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()
const contract = new ethers.Contract(
TOKEN_FACTORY_ADDRESS,
FACTORY_ABI,
signer
)
setFactory(contract)
}
setup()
}, [])
const createToken = async (metadata: TokenMetadata) => {
if (!factory) throw new Error("Not connected")
return await factory.createToken(
metadata,
"",
{ value: ethers.utils.parseEther("0.001") }
)
}
const getQuote = async (tokenAddress: string, ethAmount: string) => {
if (!factory) throw new Error("Not connected")
return await factory.getQuoteBuy(
tokenAddress,
ethers.utils.parseEther(ethAmount)
)
}
return { factory, createToken, getQuote }
}
function TokenCreator() {
const { createToken } = useInkyPump()
const handleCreate = async () => {
const metadata = {
name: "My Token",
ticker: "MTK",
description: "An amazing token",
imageUrl: "https://example.com/logo.png",
telegram: "",
twitter: "",
website: "",
owner: ethers.constants.AddressZero,
createdAt: 0
}
try {
const tokenAddress = await createToken(metadata)
console.log("Token created:", tokenAddress)
} catch (error) {
console.error("Failed to create token:", error)
}
}
return (
<button onClick={handleCreate}>
Create Token
</button>
)
}
Copy
import { ethers } from 'ethers'
import dotenv from 'dotenv'
dotenv.config()
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL)
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider)
const factory = new ethers.Contract(
TOKEN_FACTORY_ADDRESS,
FACTORY_ABI,
wallet
)
async function createAndBuyToken() {
const metadata = {
name: "Bot Token",
ticker: "BOT",
description: "Automated token",
imageUrl: "https://example.com/bot.png",
telegram: "",
twitter: "",
website: "",
owner: ethers.constants.AddressZero,
createdAt: 0
}
const creationFee = ethers.utils.parseEther("0.001")
const buyAmount = ethers.utils.parseEther("0.1")
const tx = await factory.createAndBuyToken(
metadata,
"BOT_REFERRAL",
{ value: creationFee.add(buyAmount) }
)
const receipt = await tx.wait()
console.log("Token created and bought:", receipt.transactionHash)
return receipt.events[0].args.token
}
async function monitorToken(tokenAddress: string) {
const filter = factory.filters.TokenPriceUpdate(tokenAddress)
factory.on(filter, (token, pair, txType, priceData, txData) => {
console.log("Price update:", {
price: ethers.utils.formatEther(priceData.price),
trader: txData.trader,
tokenAmount: ethers.utils.formatEther(txData.tokenAmount),
ethAmount: ethers.utils.formatEther(txData.ethAmount)
})
})
}
createAndBuyToken()
.then(monitorToken)
.catch(console.error)
Copy
from web3 import Web3
from eth_account import Account
import json
w3 = Web3(Web3.HTTPProvider('https://rpc.url'))
TOKEN_FACTORY_ADDRESS = "0x1D74317d760f2c72A94386f50E8D10f2C902b899"
with open('factory_abi.json') as f:
FACTORY_ABI = json.load(f)
factory = w3.eth.contract(
address=TOKEN_FACTORY_ADDRESS,
abi=FACTORY_ABI
)
private_key = "YOUR_PRIVATE_KEY"
account = Account.from_key(private_key)
def create_token(metadata, referral=""):
txn = factory.functions.createToken(
metadata,
referral
).build_transaction({
'from': account.address,
'value': w3.to_wei(0.001, 'ether'),
'gas': 2000000,
'gasPrice': w3.eth.gas_price,
'nonce': w3.eth.get_transaction_count(account.address),
})
signed = account.sign_transaction(txn)
tx_hash = w3.eth.send_raw_transaction(signed.rawTransaction)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
return receipt
def buy_tokens(token_address, eth_amount, referral=""):
quote = factory.functions.getQuoteBuy(
token_address,
w3.to_wei(eth_amount, 'ether')
).call()
print(f"Expected tokens: {w3.from_wei(quote, 'ether')}")
txn = factory.functions.buy(
token_address,
referral
).build_transaction({
'from': account.address,
'value': w3.to_wei(eth_amount, 'ether'),
'gas': 300000,
'gasPrice': w3.eth.gas_price,
'nonce': w3.eth.get_transaction_count(account.address),
})
signed = account.sign_transaction(txn)
tx_hash = w3.eth.send_raw_transaction(signed.rawTransaction)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
return receipt
Error Handling
Copy
async function safeTransaction(fn: () => Promise<any>) {
try {
return await fn()
} catch (error: any) {
if (error.code === 'ACTION_REJECTED') {
console.log("User rejected transaction")
return null
}
if (error.reason) {
switch(error.reason) {
case "InsufficientETH":
alert("Not enough ETH for this transaction")
break
case "TokenNotFunding":
alert("This token has already graduated")
break
case "InvalidAmount":
alert("Invalid amount specified")
break
default:
alert(`Transaction failed: ${error.reason}`)
}
return null
}
console.error("Unknown error:", error)
throw error
}
}
const result = await safeTransaction(async () => {
return await factory.buy(tokenAddress, "", { value: amount })
})
Gas Optimization
Batch Reading
Batch Reading
Copy
const multicall = new ethers.Contract(MULTICALL_ADDRESS, MULTICALL_ABI, provider)
const calls = tokens.map(token => ({
target: TOKEN_FACTORY_ADDRESS,
callData: factory.interface.encodeFunctionData('getQuoteBuy', [token, amount])
}))
const results = await multicall.aggregate(calls)
Gas Estimation
Gas Estimation
Copy
async function estimateGas(tokenAddress: string, ethAmount: string) {
const gasEstimate = await factory.estimateGas.buy(
tokenAddress,
"",
{ value: ethers.utils.parseEther(ethAmount) }
)
const gasPrice = await provider.getGasPrice()
const gasCost = gasEstimate.mul(gasPrice)
console.log(`Estimated gas: ${ethers.utils.formatEther(gasCost)} ETH`)
return gasCost
}
Event Monitoring
Copy
function listenToEvents(tokenAddress: string) {
const filter = factory.filters.TokenPriceUpdate(tokenAddress)
factory.on(filter, (
token,
pair,
txType,
priceData,
txData,
referral
) => {
console.log("Price update:", {
token,
type: txType,
price: ethers.utils.formatEther(priceData.price),
trader: txData.trader,
tokenAmount: ethers.utils.formatEther(txData.tokenAmount),
ethAmount: ethers.utils.formatEther(txData.ethAmount)
})
})
return () => factory.removeAllListeners(filter)
}