SDK for interacting with Bondkit smart contracts, allowing you to deploy and manage Bondkit tokens.
Install the package using npm or yarn:
npm install @b3dotfun/bondkit
# or
yarn add @b3dotfun/bondkit
This SDK uses viem
as a peer dependency for interacting with the Ethereum blockchain. You will need to have viem
installed in your project.
npm install viem
# or
yarn add viem
Here's a quick example of how to use the SDK:
import {
BondkitTokenFactory,
BondkitToken,
getConfig,
// sepolia, // Example chain from viem/chains if you re-export it or guide users to import it
} from '@b3dotfun/bondkit';
import { sepolia } from 'viem/chains'; // Or import directly
import type { EIP1193Provider } from 'viem';
// Ensure you have an EIP-1193 provider (e.g., from MetaMask or WalletConnect)
// declare let window: any; // For browser environment
// const provider: EIP1193Provider = window.ethereum;
async function main() {
// --- Configuration ---
const chainId = sepolia.id; // Example: Sepolia testnet
// Get chain-specific configuration (RPC URL, factory addresses)
const sdkConfig = getConfig(chainId);
console.log(`Using factory: ${sdkConfig.factoryAddress} on chain ${sdkConfig.chain.name}`);
// --- Initialize Factory ---
// For read-only operations or if walletKey is managed internally by provider:
const factory = new BondkitTokenFactory(chainId);
// For write operations, connect with a provider (e.g., from a browser wallet)
// if (provider) {
// const connected = factory.connect(provider);
// if (!connected) {
// console.error("Failed to connect factory to provider");
// return;
// }
// console.log("Factory connected to provider.");
// } else {
// console.log("No provider found. Factory initialized with default RPC for read-only operations.");
// }
// Example: Get deployed tokens (read operation)
try {
const deployedTokens = await factory.getDeployedBondkitTokens();
console.log("Deployed Bondkit Tokens:", deployedTokens);
if (deployedTokens.length > 0) {
const firstTokenAddress = deployedTokens[0];
console.log(`\n--- Interacting with token: ${firstTokenAddress} ---`);
const token = new BondkitToken(chainId, firstTokenAddress as string);
// if (provider) token.connect(provider);
const name = await token.name();
const symbol = await token.symbol();
const totalSupply = await token.totalSupply();
console.log(`Token Name: ${name}`);
console.log(`Token Symbol: ${symbol}`);
console.log(`Total Supply: ${totalSupply}`);
// Further interactions (buy, sell, etc.) would require a connected wallet with funds.
// Example: const buyTxHash = await token.buy(parseEther("1"), parseEther("0.01"));
// console.log("Buy transaction hash:", buyTxHash);
}
} catch (error) {
console.error("Error fetching deployed tokens or token details:", error);
}
// --- Deploying a new token (example, requires connected wallet with factory owner/deployer privileges) ---
/*
if (provider && factory.getOwner() === YOUR_DEPLOYER_ADDRESS) { // Pseudo-code for owner check
try {
const newTokenConfig = {
name: "My New Bondkit Token",
symbol: "MBNT",
artist: "0xYourArtistAddressHere", // Replace with actual artist address
finalTokenSupply: 1000000n * (10n ** 18n), // 1 million tokens with 18 decimals
aggressivenessFactor: 50, // Example value (0-100)
lpSplitRatioArtistBps: 1000n, // Example: 10% to artist in BPS (1000 / 10000)
dexTriggerThresholdEth: 1n * (10n ** 18n), // Example: 1 ETH
uniswapV2RouterAddress: "0xYourRouterAddressHere", // Replace with actual Uniswap V2 compatible router
migrationAdminAddress: "0xYourMigrationAdminAddressHere", // Replace with actual admin address
};
console.log("\nAttempting to deploy new token...");
const newTokenAddress = await factory.deployBondkitToken(newTokenConfig);
console.log(`New token deployed at: ${newTokenAddress}`);
} catch (error) {
console.error("Error deploying new token:", error);
}
}
*/
}
main().catch(console.error);
Detailed examples can be found in the examples
directory of this repository:
-
examples/01-read-operations.ts
: Demonstrates read-only interactions, such as fetching token details, factory information, and bonding curve data. -
examples/02-transactions-buy-sell.ts
: Shows how to perform transactions like buying and selling tokens. Requires a private key with test funds. -
examples/03-deploy-token.ts
: Illustrates deploying a new Bondkit token using the factory. Requires a private key with deployer permissions and funds for gas.
To run these examples, you'll typically use a tool like ts-node
:
# Ensure you are in the root of the bondkit-sdk project
# You might need to install ts-node globally or as a dev dependency
# npm install -g ts-node
# or
# npm install --save-dev ts-node
# Before running, ensure you have:
# 1. Installed dependencies: npm install
# 2. Replaced placeholder values (like YOUR_INFURA_PROJECT_ID, private keys, etc.) within the example files.
# 3. Updated src/constants.ts with your Infura Project ID and correct contract addresses.
ts-node examples/01-read-operations.ts
ts-node examples/02-transactions-buy-sell.ts
ts-node examples/03-deploy-token.ts
-
Deploy New Tokens: Use
BondkitTokenFactory.deployBondkitToken()
. -
Manage Existing Tokens: Interact with token instances using the
BondkitToken
class.- Read token details (name, symbol, totalSupply, owner, etc.).
- ERC20 operations:
balanceOf
,transfer
,approve
,allowance
. - Bonding curve interactions:
buy
,sell
,getAmountOfTokensToBuy
,getAmountOfEthToSell
. - Lifecycle management:
migrateToDex
,transferOwnership
.
-
Configuration: Get chain-specific configurations using
getConfig()
.
Remember to replace placeholder addresses and values in the usage example with actual data for testing.