sell()
Sell a specified amount of tokens to receive SOL.
sell(options: SellOptions): Promise<TransactionResult>Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
mint | string | Yes | Token mint address to sell |
tokenAmount | number | Yes | Amount of tokens to sell |
slippage | number | Yes | Slippage tolerance (0.01 = 1%, 0.05 = 5%) |
priority | Priority | Yes | Transaction priority ('economy', 'fast', 'faster', 'fastest') |
maxPriorityCost | number | No | Maximum priority fee in SOL |
Return Value
Section titled “Return Value”Returns a TransactionResult object with transaction details and trade amounts.
interface TransactionResult { signature: string; // Transaction signature (use for block explorers) status: string; // Transaction status (e.g., "confirmed") slot: number; // Solana slot number where transaction landed platform: string; // Trading platform (e.g., "pump_fun") inputMint: string; // Input token mint address (token for sell) outputMint: string; // Output token mint address (SOL for sell) tradeResult: { inputAmount: number; // Amount of tokens sold (actual on-chain amount) outputAmount: number; // Amount of SOL received (actual on-chain amount) }; priorityCost: number; // Priority fee cost in SOL}Example
Section titled “Example”import { DarkfibreSDK } from '@darkfibre/sdk';
const sdk = new DarkfibreSDK({ apiKey: 'your-api-key', privateKey: 'your-base58-private-key',});
const result = await sdk.sell({ mint: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', // BONK tokenAmount: 1000.55, slippage: 0.05, priority: 'fast',});
console.log('Transaction:', result.signature);console.log('Tokens sold:', result.tradeResult.inputAmount);console.log('SOL received:', result.tradeResult.outputAmount);console.log('Priority fee:', result.priorityCost, 'SOL');- Mode: This is an
exactInoperation. You specify the exact tokens to sell, and receive an estimated SOL amount. - Slippage: The maximum price change you are willing to accept during the trade.
0.05means5%, anything worse and the transaction fails. - Priority: Higher priority means faster execution but higher network fees.
- Input/Output perspective: The
inputMintandoutputMintfields in the response are from the DEX’s perspective (what goes into the DEX vs what comes out). For a sell operation,inputMintis the token (what the DEX receives) andoutputMintis SOL (what the DEX sends out).
Related
Section titled “Related”- buy() - Buy tokens with SOL
- swap() - Generic swap endpoint
- Priority - Priority explained
- POST /v1/tx/sell - Underlying API endpoint
- POST /v1/tx/submit - Submit API endpoint reference