SteelSwapClient
The main client class for interacting with the SteelSwap v1 API.
Constructor
new SteelSwapClient(config?: SteelSwapConfig)See Configuration for available options.
Swap Methods
estimateSwap(params)
Estimate a token swap and get routing information across DEXs.
const estimate = await client.estimateSwap({
tokenA: 'lovelace',
tokenB: 'policy.asset',
quantity: 10_000_000,
hop: false,
})Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
tokenA | string | Yes | Input token ("lovelace" for ADA, or hex policy ID + asset name) |
tokenB | string | Yes | Output token |
quantity | NumericInput | Yes | Amount in smallest unit |
predictFromOutputAmount | boolean | No | Calculate input from desired output |
ignoreDexes | string[] | No | DEXs to exclude from routing |
hop | boolean | No | Enable multi-hop routing |
da | object[] | string | null | No | Additional data |
Returns: Promise<SplitOutput<F> | HopSplitOutput<F>>
The response contains tokenA, tokenB, quantityA, quantityB, totalFee, totalDeposit, steelswapFee, bonusOut, price, and pools. For multi-hop swaps (hop: true), the response includes splitGroup: SplitOutput[][] and the top-level pools field is omitted — pools only exist inside each splitGroup entry.
buildSwap(params)
Build an unsigned swap transaction.
const result = await client.buildSwap({
tokenA: 'lovelace',
tokenB: 'policy.asset',
quantity: 10_000_000,
address: 'addr1...',
utxos: ['txhash#0'],
slippage: 100,
})Parameters:
Includes all estimateSwap parameters plus:
| Name | Type | Required | Description |
|---|---|---|---|
address | string | Yes | Sender's bech32 address |
utxos | string[] | Yes | Available UTXOs |
slippage | NumericInput | Yes | Slippage in basis points |
collateral | string[] | No | Collateral UTXOs |
changeAddress | string | object | No | Change address |
forwardAddress | string | No | Address to forward output to |
pAddress | string | No | Payment address |
feeAdust | boolean | No | Adjust fees automatically (note: API spells this "feeAdust") |
ttl | number | No | Time-to-live in seconds (default: 900) |
Returns: Promise<BuildSwapResponse> — { tx: string, p: boolean }
cancelSwap(params)
Create a cancellation transaction for pending swaps.
const tx = await client.cancelSwap({
txList: [{ txHash: 'abc...', txIndex: 0 }],
ttl: 900,
})Returns: Promise<string> - Unsigned transaction hex
Token Methods
getTokens()
Get list of all available tokens.
const tokens = await client.getTokens()Returns: Promise<TokenSummary[]>
getTokenPriceUsd(token)
Get token price in USD (as millionths).
const price = await client.getTokenPriceUsd('policy.asset')
// 621512 = $0.621512Returns: Promise<NumericOutput<F> | null>
getTokenIconUrl(token)
Get the URL for a token's icon image (PNG). No network request is made — use the returned URL directly in <img> tags and let the browser fetch and cache the image.
const iconUrl = client.getTokenIconUrl('policy.asset')
// Use in HTML: <img src={iconUrl} />Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
token | string | Yes | Token identifier (policy ID + asset name, or "lovelace") |
Returns: string
findTradingPairs(token)
Find tokens that can be traded for a given token.
const pairs = await client.findTradingPairs('policy.asset')Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
token | string | Yes | Token identifier (policy ID + asset name, or "lovelace") |
Returns: Promise<TokenSummary[]>
getOrders(params)
Get global swap orders for a token pair.
const orders = await client.getOrders({
tokenA: 'lovelace',
tokenB: 'policy.asset',
limit: 10,
})Returns: Promise<OrderStatusResponse> — { orders, page, lastPage }
getPools(params)
Get DEX pool information for a token pair.
const pools = await client.getPools({
tokenA: 'lovelace',
tokenB: 'policy.asset',
})
// Returns Record<string, PoolSummary> (keyed by DEX name)Returns: Promise<Record<string, PoolSummary<F>>> — A map from DEX name to pool summary.
Wallet Methods
getWalletHistory(params)
Get swap history for wallet addresses.
const history = await client.getWalletHistory({
addresses: ['addr1...'],
page: 0,
pageSize: 25,
})Returns: Promise<OrderStatusResponse> — { orders, page, lastPage }
getWalletPending(params)
Get pending swap orders for wallet addresses.
const pending = await client.getWalletPending({
addresses: ['addr1...'],
})Returns: Promise<OrderStatusResponse>
notifySubmitted(params)
Notify the backend of a submitted transaction.
await client.notifySubmitted({
txHash: 'abc123...',
})Returns: Promise<void>
Utility Methods
getDexList()
Get list of available DEXs.
const dexes = await client.getDexList()
// ['sundaeswap', 'minswap', 'wingriders', ...]Returns: Promise<string[]>
getStatistics()
Get SteelSwap usage statistics.
const stats = await client.getStatistics()
console.log(stats.service) // "steelswap"
console.log(stats.totalWallets) // numeric valueReturns: Promise<SteelSwapStatistics<F> | null>
Error Handling
The client throws SteelSwapError for API errors and SteelSwapValidationError for response shape mismatches:
import { SteelSwapError, SteelSwapValidationError } from '@steelswap/steelswap-sdk'
try {
await client.estimateSwap({ ... })
} catch (error) {
if (error instanceof SteelSwapValidationError) {
// API returned data that doesn't match the expected schema
console.log('Endpoint:', error.endpoint)
console.log('Validation error:', error.validationError)
console.log('Raw data:', error.rawData)
} else if (error instanceof SteelSwapError) {
// API returned an HTTP error
console.log('Status:', error.statusCode)
console.log('Body:', error.responseBody)
}
}SteelSwapValidationError extends SteelSwapError, so existing catch (e instanceof SteelSwapError) blocks will still catch validation errors.