Skip to content

Build a transaction

When you call sdk.buy(), the SDK first calls this endpoint (POST /v1/tx/buy) to build an unsigned transaction. This page explains what happens under the hood.

You build an unsigned transaction via REST, then sign it locally. The API constructs an optimized transaction with the correct accounts, instructions and a fresh blockhash.

POST /v1/tx/buy
{
"mint": "TOKEN_MINT_ADDRESS",
"solAmount": 0.002,
"slippage": 0.05,
"priority": "fast"
}

Fields:

  • mint: Token address you want to buy
  • solAmount: Amount of SOL to spend
  • slippage: Maximum allowed slippage (0.05 = 5%)
  • priority: Transaction priority (economy, fast, faster, fastest) - see Priority

The API returns several critical pieces:

  • submissionToken: Links this transaction server-side. You’ll need this when submitting.
  • unsignedTransaction: Base64-encoded wire transaction ready for signing. Don’t modify this.
  • expiresAt: ~30 second validity window due to Solana blockhash expiry. Sign and submit quickly.
  • estimates: Pre-execution estimates for input/output amounts and price impact.
  • priorityCost: The actual priority fee for this transaction. Check this before signing if you have cost limits.

For complete API reference, see: POST /v1/tx/buy.

import axios from 'axios';
const API_KEY = 'api_your_key_here';
const API_BASE_URL = 'https://api.darkfibre.dev/v1';
const api = axios.create({
baseURL: API_BASE_URL,
headers: { 'Authorization': `Bearer ${API_KEY}` },
timeout: 30000,
});
async function buildBuyTransaction() {
const response = await api.post('/tx/buy', {
mint: 'TOKEN_MINT_ADDRESS',
solAmount: 0.002,
slippage: 0.05,
priority: 'fast',
});
const { submissionToken, unsignedTransaction, expiresAt, priorityCost } = response.data.data;
console.log('Submission token:', submissionToken);
console.log('Expires at:', expiresAt);
console.log('Priority cost:', priorityCost, 'SOL');
return { submissionToken, unsignedTransaction };
}
buildBuyTransaction().catch(console.error);

The response contains several important fields:

  • submissionToken: Links this transaction server-side. You’ll need this when submitting.
  • unsignedTransaction: Base64-encoded wire transaction ready for signing.
  • expiresAt: ~30s validity window due to blockhash expiry.
  • estimates: Pre-execution estimates for input/output amounts and price impact.
  • priorityCost: The actual priority fee for this transaction. Check this before signing if you have cost limits.