Configuration
Client Options
The SteelSwapClient accepts a configuration object with the following options:
import { SteelSwapClient } from 'steelswap-sdk'
const client = new SteelSwapClient({
baseUrl: 'https://apidev.steelswap.io', // API base URL
timeout: 30000, // Request timeout in ms
token: 'd82983fe50d8eae...', // Authentication token
partner: 'eternl', // Partner identifier
numericFormat: 'string', // Output format for numbers
fetch: customFetch, // Custom fetch implementation
})token
- Type:
string - Default:
undefined
Authentication token sent as the token header on all API requests.
const client = new SteelSwapClient({
token: 'd82983fe50d8eae11f3fa2dd66ddfe658420c9474a9410c44943a71937c35f07',
})partner
- Type:
Partner - Default:
undefined
Partner identifier automatically injected into swap requests (estimateSwap, buildSwap, cancelSwap). Valid values:
''(empty string)'eternl''eternl-aggregator''eternl-browser''farmbot''lace-aggregator''yoroi-aggregator'
const client = new SteelSwapClient({
partner: 'eternl',
})
// Partner is automatically included in swap requests
await client.estimateSwap({
tokenA: '',
tokenB: 'policy.asset',
quantity: '10000000',
})numericFormat
- Type:
'string' | 'number' | 'bigint' | 'Big' - Default:
'string'
Controls the format of numeric values in API responses. The client is generic and TypeScript will infer the correct return types based on your choice.
// Default: strings (safest for large numbers)
const stringClient = new SteelSwapClient({ numericFormat: 'string' })
const estimate1 = await stringClient.estimateSwap({ ... })
estimate1.totalOutput // type: string
// JavaScript numbers (convenient but may lose precision for large values)
const numberClient = new SteelSwapClient({ numericFormat: 'number' })
const estimate2 = await numberClient.estimateSwap({ ... })
estimate2.totalOutput // type: number
// BigInt (for integer precision)
const bigintClient = new SteelSwapClient({ numericFormat: 'bigint' })
const estimate3 = await bigintClient.estimateSwap({ ... })
estimate3.totalOutput // type: bigint
// Big.js instances (for decimal precision and calculations)
const bigClient = new SteelSwapClient({ numericFormat: 'Big' })
const estimate4 = await bigClient.estimateSwap({ ... })
estimate4.totalOutput // type: Big
estimate4.totalOutput.times('0.997') // Big.js methods availablebaseUrl
- Type:
string - Default:
'https://apidev.steelswap.io'
The base URL for the SteelSwap API.
timeout
- Type:
number - Default:
30000
Request timeout in milliseconds. Requests that take longer will be aborted.
fetch
- Type:
typeof fetch - Default: Global
fetch
Custom fetch implementation. Useful for:
- Request/response logging
- Using a different HTTP client
Working with Numbers
Input
All numeric values (quantities, slippage, etc.) can be passed as:
- Strings:
'10000000' - BigInt:
10000000n - Big.js instances:
new Big('10000000')
import Big from 'big.js'
// All of these work regardless of numericFormat
await client.estimateSwap({
tokenA: '',
tokenB: 'policy.asset',
quantity: '10000000', // string
})
await client.estimateSwap({
tokenA: '',
tokenB: 'policy.asset',
quantity: 10000000n, // bigint
})
const amount = new Big('10000000')
await client.estimateSwap({
tokenA: '',
tokenB: 'policy.asset',
quantity: amount, // Big instance
})Output
Output format is controlled by numericFormat. Choose based on your needs:
| Format | Type | Best For |
|---|---|---|
'string' | string | Default, safe for any size, easy serialization |
'number' | number | Simple math, small values (< 2^53) |
'bigint' | bigint | Large integers, native JS support |
'Big' | Big | Decimal precision, complex calculations |
// Example with Big.js for calculations
const client = new SteelSwapClient({ numericFormat: 'Big' })
const estimate = await client.estimateSwap({ ... })
// Direct calculations on response values
const withSlippage = estimate.totalOutput.times('0.99')
const formatted = estimate.totalOutput.div(1_000_000).toFixed(2) // "50.00" ADACustom Fetch Example
const customFetch: typeof fetch = async (url, options) => {
console.log('Request:', url)
const response = await fetch(url, {
...options,
headers: {
...options?.headers,
'X-Custom-Header': 'value',
},
})
console.log('Response:', response.status)
return response
}
const client = new SteelSwapClient({
fetch: customFetch,
})Environment-Specific Setup
Node.js
The SDK works out of the box in Node.js 18+ which includes native fetch.
For older Node.js versions, use a fetch polyfill:
import fetch from 'node-fetch'
const client = new SteelSwapClient({
fetch: fetch as unknown as typeof globalThis.fetch,
})Browser
No additional setup required. The SDK uses the native fetch API.
React Native
// React Native has built-in fetch support
const client = new SteelSwapClient()