Quick Start
Minimal example: buy tokens using the SDK in under 30 lines.
git clone https://github.com/darkfibre-dev/darkfibre-examples.gitcd darkfibre-examples/01-quick-startnpm installcp .env.example .envEdit .env with your credentials:
DARKFIBRE_API_KEY=your-api-keySOLANA_PRIVATE_KEY=your-base58-private-keyEdit index.ts to set the token mint address you want to buy.
npm startimport { DarkfibreSDK } from '@darkfibre/sdk';import 'dotenv/config';
async function main() { const sdk = new DarkfibreSDK({ apiKey: process.env.DARKFIBRE_API_KEY!, privateKey: process.env.SOLANA_PRIVATE_KEY!, });
// Replace with the token address you want to buy const TOKEN_ADDRESS = 'PASTE_YOUR_TOKEN_ADDRESS_HERE';
const result = await sdk.buy({ mint: TOKEN_ADDRESS, solAmount: 0.005, slippage: 0.05, priority: 'fast', });
console.log('Transaction:', result.signature); console.log('SOL spent:', result.tradeResult.inputAmount); console.log('Tokens received:', result.tradeResult.outputAmount); console.log('Priority fee:', result.priorityCost, 'SOL'); console.log(`View on Solscan: https://solscan.io/tx/${result.signature}`);}
main().catch(console.error);What It Does
Section titled “What It Does”- Initializes the SDK with your credentials
- Buys tokens with 0.005 SOL
- Prints the transaction signature and tokens received
Configuration
Section titled “Configuration”Edit index.ts to change:
| Variable | Description | Default |
|---|---|---|
TOKEN_ADDRESS | Token mint address to buy | - |
solAmount | Amount of SOL to spend | 0.005 |
slippage | Slippage tolerance (0.05 = 5%) | 0.05 |
priority | Transaction priority | 'fast' |
Expected Output
Section titled “Expected Output”Transaction: 5xK7j...abc123SOL spent: 0.005Tokens received: 1234567.89Priority fee: 0.0001 SOLView on Solscan: https://solscan.io/tx/5xK7j...abc123Related
Section titled “Related”- SDK Overview - Installation and setup
- buy() - Full method documentation