SDK
The official Darkfibre TypeScript SDK wraps the complete build-sign-submit flow into simple method calls. Your private keys never leave your device.
Installation
Section titled “Installation”The SDK is published as a standard npm package: @darkfibre/sdk.
npm install @darkfibre/sdkQuick Example
Section titled “Quick Example”import { DarkfibreSDK } from '@darkfibre/sdk';
const sdk = new DarkfibreSDK({ apiKey: 'your-api-key', privateKey: 'your-base58-private-key',});
const result = await sdk.buy({ mint: 'token-mint-address', solAmount: 0.01, slippage: 0.05, priority: 'fast',});
console.log('Transaction:', result.signature);console.log('Tokens received:', result.tradeResult.outputAmount);That’s it! The SDK just handled building the transaction, signing with your private key, submitting to blockchain and returning the confirmed result. All in one async call.
Getting an API Key
Section titled “Getting an API Key”Before you can trade, you need a Darkfibre API key. There are two ways to get one:
- Browser registration (recommended): darkfibre.dev/register
- Programmatic registration: Use
DarkfibreSDK.register()
Constructor Options
Section titled “Constructor Options”| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | Your Darkfibre API key |
privateKey | string | Yes | Base58-encoded Solana private key (32 or 64 bytes) |
The SDK constructor is where you establish your authenticated connection. Your API key identifies your account while your private key stays local. It’s only used on your device to sign transactions before they’re sent to for submission.
Environment Variables
Section titled “Environment Variables”For anything beyond quick testing, credentials should live outside your source code. Create .env in the folowing format:
DARKFIBRE_API_KEY=api_your_key_hereSOLANA_PRIVATE_KEY=your_base58_private_keyimport { DarkfibreSDK } from '@darkfibre/sdk';import 'dotenv/config';
const sdk = new DarkfibreSDK({ apiKey: process.env.DARKFIBRE_API_KEY!, privateKey: process.env.SOLANA_PRIVATE_KEY!,});How It Works
Section titled “How It Works”At a high level, every trade follows the same four-step lifecycle. Understanding the flow helps you debug issues and optimize your integration.
Here’s what happens under the hood when you call sdk.buy():
sequenceDiagram
participant App as Your App
participant SDK as Darkfibre SDK
participant API as Darkfibre API
participant Chain as Solana
App->>SDK: sdk.buy(options)
SDK->>API: POST /tx/buy
API-->>SDK: unsigned transaction
SDK->>SDK: Sign locally
SDK->>API: POST /tx/submit
API->>Chain: Submit to network
Chain-->>API: Confirmation
API-->>SDK: Transaction result
SDK-->>App: TransactionResult
- Build - SDK requests a transaction from the Darkfibre API
- Sign - Transaction is signed locally with your private key
- Submit - Signed transaction is sent for priority execution
- Result - You receive the on-chain outcome
This architecture is important: your private key never leaves your machine. The Darkfibre API builds optimized transactions for you, but you maintain complete custody by signing locally. This gives you the speed and convenience of a managed service with the security of self-custody.
Next Steps
Section titled “Next Steps”Ready to start building? Here’s where to go next based on what you want to do:
- register() - Programmatic API key registration
- buy() - Buy tokens with SOL
- sell() - Sell tokens for SOL
- swap() - Generic swap endpoint
- getProfile() - Wallet info, volume and fee tier
- SDK Quick Start - Complete buy/sell example