Skip to content

SDK

The official Darkfibre TypeScript SDK wraps the complete build-sign-submit flow into simple method calls. Your private keys never leave your device.

The SDK is published as a standard npm package: @darkfibre/sdk.

Terminal window
npm install @darkfibre/sdk
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.

Before you can trade, you need a Darkfibre API key. There are two ways to get one:

  1. Browser registration (recommended): darkfibre.dev/register
  2. Programmatic registration: Use DarkfibreSDK.register()
ParameterTypeRequiredDescription
apiKeystringYesYour Darkfibre API key
privateKeystringYesBase58-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.

For anything beyond quick testing, credentials should live outside your source code. Create .env in the folowing format:

.env
DARKFIBRE_API_KEY=api_your_key_here
SOLANA_PRIVATE_KEY=your_base58_private_key
import { DarkfibreSDK } from '@darkfibre/sdk';
import 'dotenv/config';
const sdk = new DarkfibreSDK({
apiKey: process.env.DARKFIBRE_API_KEY!,
privateKey: process.env.SOLANA_PRIVATE_KEY!,
});

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
  1. Build - SDK requests a transaction from the Darkfibre API
  2. Sign - Transaction is signed locally with your private key
  3. Submit - Signed transaction is sent for priority execution
  4. 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.

Ready to start building? Here’s where to go next based on what you want to do: