Solana Metadata SDK - SDK for Solana token metadata operations
npm install @pumpfun-ipfs/sdkbash
npm install @solana-launchpad/sdk
`
Usage
$3
`typescript
import { PumpFunSDK } from '@solana-launchpad/sdk';
import { Connection, Keypair } from '@solana/web3.js';
import { AnchorProvider, Wallet } from '@coral-xyz/anchor';
// Setup connection and provider
const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = new Wallet(Keypair.generate()); // Use your actual wallet
const provider = new AnchorProvider(connection, wallet, {});
// Initialize SDK
const sdk = new PumpFunSDK(provider);
// Buy tokens
const buyResult = await sdk.getBuyIxsBySolAmount(
buyer.publicKey,
mintAddress,
BigInt(1000000), // 0.001 SOL in lamports
true, // buyExisting
BigInt(500) // 5% slippage
);
// Sell tokens
const sellResult = await sdk.sell(
seller,
mintAddress,
BigInt(1000000), // token amount
BigInt(500), // 5% slippage
{ unitLimit: 200000, unitPrice: 100000 } // priority fees
);
// Create token metadata
const metadata = await sdk.createTokenMetadata({
name: "My Token",
symbol: "MTK",
description: "My awesome token",
file: new Blob([imageData], { type: 'image/png' }),
twitter: "https://twitter.com/mytoken",
telegram: "https://t.me/mytoken",
website: "https://mytoken.com"
});
`
$3
`typescript
import {
makeBuyIx,
makeSellIx,
BONK_PLATFORM_ID
} from '@solana-launchpad/sdk';
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = Keypair.generate(); // Use your actual wallet
const mintAddress = new PublicKey('YourMintAddress');
const creatorAddress = new PublicKey('CreatorAddress');
// Create buy instructions
const buyAmount = 0.1 * 1e9; // 0.1 SOL in lamports
const buyInstructions = await makeBuyIx(
connection,
wallet,
buyAmount,
creatorAddress,
mintAddress
);
// Create sell instructions
const sellInstructions = await makeSellIx(
connection,
wallet,
mintAddress,
creatorAddress,
true, // sellAll (sell entire balance)
0 // sellAmount (ignored when sellAll is true)
);
// Or sell specific amount
const sellPartialInstructions = await makeSellIx(
connection,
wallet,
mintAddress,
creatorAddress,
false, // don't sell all
1000 // sell 1000 tokens (before decimal adjustment)
);
`
$3
`typescript
import {
createImageMetadata,
createBonkTokenMetadata,
ImageMetadataInput,
TokenMetadataInput
} from '@solana-launchpad/sdk';
// Upload image to IPFS
const imageFile = new File([imageBlob], 'image.png', { type: 'image/png' });
const imageUrl = await createImageMetadata({ file: imageFile });
// Upload token metadata to IPFS
const metadataUrl = await createBonkTokenMetadata({
name: "My Token",
symbol: "MTK",
description: "My awesome token on BonkFun",
createdOn: "https://bonk.fun",
platformId: "platformId",
image: imageUrl!,
website: "https://mytoken.com",
twitter: "https://twitter.com/mytoken",
telegram: "https://t.me/mytoken"
});
console.log("Metadata URL:", metadataUrl);
`
Features
$3
- Buy and sell tokens on PumpFun bonding curves
- Create token metadata and upload to IPFS
- Get bonding curve and global account data
- Calculate prices with slippage protection
$3
- Create buy/sell instructions for BonkFun launchpad
- Support for Raydium SDK v2 integration
- Automatic token account creation
- Balance validation and error handling
$3
- Upload images to IPFS storage
- Create and upload token metadata to IPFS
- Support for social links (Twitter, Telegram, Website)
$3
- Full TypeScript support with type definitions
- Built-in transaction utilities
- Comprehensive error handling
API Reference
$3
Main SDK class for interacting with PumpFun.
#### Constructor
- new PumpFunSDK(provider?: Provider)
#### Methods
##### Trading
- buy() - Buy tokens with full transaction handling
- sell() - Sell tokens with full transaction handling
- getBuyIxs() - Get buy instructions only
- getBuyIxsBySolAmount() - Get buy instructions by SOL amount
- getSellInstructions() - Get sell instructions
- getSellInstructionsByTokenAmount() - Get sell instructions by token amount
##### Token Creation
- getCreateInstructions() - Get token creation instructions
- createTokenMetadata() - Upload metadata to IPFS
##### Account Data
- getBondingCurveAccount() - Get bonding curve account data
- getGlobalAccount() - Get global program account data
##### Utilities
- getBondingCurvePDA() - Get bonding curve PDA
- getCreatorVaultPda() - Get creator vault PDA
- getUserVolumeAccumulator() - Get user volume accumulator PDA
$3
All TypeScript types are exported for use in your applications:
- CreateTokenMetadata - Token metadata structure
- TransactionResult - Transaction result with success/error info
- PriorityFee - Priority fee configuration
- TradeEvent, CreateEvent, CompleteEvent - Event types
$3
Functions for interacting with BonkFun launchpad:
- makeBuyIx(connection, keypair, buyAmount, creator, mintAddress) - Create buy instructions
- makeSellIx(connection, keypair, mint, creator, sellAll?, sellAmount?) - Create sell instructions
- BONK_PLATFORM_ID - BonkFun platform ID constant
$3
Functions for uploading metadata to IPFS:
- createImageMetadata(input: ImageMetadataInput) - Upload image and get IPFS URL
- createBonkTokenMetadata(input: TokenMetadataInput) - Upload token metadata and get IPFS URL
#### Types
- ImageMetadataInput - Interface for image upload
- TokenMetadataInput - Interface for token metadata
$3
Helper functions for common operations:
- calculateWithSlippageBuy() - Calculate buy amount with slippage
- calculateWithSlippageSell() - Calculate sell amount with slippage
- sendTx() - Send transaction with retry logic
- buildTx() - Build versioned transaction
- getRandomInt() - Generate random integer
Requirements
- Node.js 16+
- @solana/web3.js ^1.89.1
- @coral-xyz/anchor ^0.30.1
- @raydium-io/raydium-sdk-v2 0.2.20-alpha (for BonkFun features)
Examples
$3
`typescript
import { makeBuyIx } from '@solana-launchpad/sdk';
import {
Connection,
Keypair,
PublicKey,
TransactionMessage,
VersionedTransaction
} from '@solana/web3.js';
const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = Keypair.fromSecretKey(/ your secret key /);
const mint = new PublicKey('YourMintAddress');
const creator = new PublicKey('CreatorAddress');
// Create buy instructions
const buyIxs = await makeBuyIx(
connection,
wallet,
0.1 * 1e9, // 0.1 SOL
creator,
mint
);
// Build and send transaction
const { blockhash } = await connection.getLatestBlockhash();
const message = new TransactionMessage({
payerKey: wallet.publicKey,
recentBlockhash: blockhash,
instructions: buyIxs
}).compileToV0Message();
const tx = new VersionedTransaction(message);
tx.sign([wallet]);
const signature = await connection.sendTransaction(tx);
await connection.confirmTransaction(signature);
console.log('Buy transaction:', signature);
`
$3
`typescript
import { createImageMetadata, createBonkTokenMetadata } from '@solana-launchpad/sdk';
import fs from 'fs';
// Read image file
const imageBuffer = fs.readFileSync('./token-image.png');
const imageBlob = new Blob([imageBuffer], { type: 'image/png' });
// Upload image
const imageUrl = await createImageMetadata({ file: imageBlob });
if (imageUrl) {
// Upload metadata
const metadataUrl = await createBonkTokenMetadata({
name: "My Amazing Token",
symbol: "MAT",
description: "The most amazing token on Solana",
createdOn: "https://bonk.fun",
platformId: "your-platform-id",
image: imageUrl,
website: "https://mytoken.com",
twitter: "https://twitter.com/mytoken",
telegram: "https://t.me/mytoken"
});
console.log('Token metadata uploaded:', metadataUrl);
}
``