Skip to content
TokenFlight SDK

API Reference

The only supported public component. One class and one HTML tag cover swap and receive.

app.js
import { TokenFlightWidget } from '@tokenflight/swap';
const widget = new TokenFlightWidget({
container: '#widget',
config: {
toToken: { chainId: 8453, address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' },
tradeType: 'EXACT_OUTPUT',
amount: '100',
theme: 'dark',
},
walletAdapter: myAdapter,
callbacks: {},
});
PropertyTypeDefaultDescription
toTokenTokenIdentifier | TokenIdentifier[]Destination token or token list
fromTokenTokenIdentifierOptional source token
tradeType'EXACT_INPUT' | 'EXACT_OUTPUT''EXACT_INPUT'Swap vs fixed-output receive
amountstringAmount value in human-readable units
theme'dark' | 'light' | 'auto''light'Widget color theme
localestring'en-US'Display locale
apiEndpointstring'https://api.hyperstream.dev'API endpoint
fiatApiEndpointstringFiat API endpoint
recipientstringCustom recipient address
iconstringCustom icon URL for the target token
fromTokensTokenIdentifier[]Source token allowlist
toTokensTokenIdentifier[]Destination token allowlist
lockFromTokenbooleanfalseLock the source token selector
lockToTokenbooleanfalseLock the destination token selector
customColorsRecord<string, string>CSS color variable overrides
titleTextstringCustom widget title text
titleImageUrlstringCustom widget title image URL
hideTitlebooleanfalseHide the top title/header area
hidePoweredBybooleanfalseHide the footer
noBackgroundbooleanfalseRemove container background
noBorderbooleanfalseRemove container border and shadow
index.html
<tokenflight-widget
theme="dark"
locale="en-US"
to-token="eip155:8453:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
trade-type="EXACT_OUTPUT"
amount="100"
from-token="eip155:1:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
csp-nonce="abc123"
></tokenflight-widget>
AttributeDescription
to-tokenDestination token in CAIP-10 or JSON format
trade-typeEXACT_INPUT or EXACT_OUTPUT
amountAmount value in human-readable units
theme'light', 'dark', or 'auto'
localeDisplay locale
from-tokenSource token in CAIP-10 or JSON format
api-endpointCustom Hyperstream API endpoint URL
fiat-api-endpointCustom fiat API endpoint URL
csp-nonceNonce for CSP-restricted environments

MethodDescription
initialize()Mount and render the widget into the container
destroy()Unmount the widget and clean up resources
setTheme(theme)Switch theme at runtime ('light', 'dark', 'auto')
setCustomColors(colors)Apply custom CSS color overrides at runtime
app.js
widget.initialize();
widget.setTheme('light');
widget.setCustomColors({ primary: '#FF6B00', background: '#1A1A2E' });
widget.destroy();

Pass callbacks to widget lifecycle events:

app.js
const widget = new TokenFlightWidget({
container: '#widget',
config: {
toToken: { chainId: 8453, address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' },
tradeType: 'EXACT_OUTPUT',
amount: '100',
theme: 'dark',
},
callbacks: {
onSwapSuccess: (data) => console.log('Success:', data),
onSwapError: (data) => console.log('Error:', data),
onQuoteReceived: (quote) => console.log('Quote:', quote),
onAmountChanged: (data) => console.log('Amount:', data),
onWalletConnected: (data) => console.log('Wallet:', data),
onConnectWallet: () => openMyWalletModal(),
onAccountModal: () => openMyAccountModal(),
},
});
CallbackPayloadDescription
onSwapSuccessSwapSuccessDataFired after a successful swap or purchase
onSwapErrorSwapErrorDataFired when execution fails
onQuoteReceivedQuoteResponseFired when a new price quote is fetched
onAmountChangedAmountChangedDataFired when the user changes an editable amount
onWalletConnectedWalletConnectedDataFired when a wallet connects
onConnectWalletCalled when the user clicks “Connect Wallet” and no walletAdapter is provided
onAccountModalCalled when the user clicks the connected wallet address
types.ts
interface SwapSuccessData {
orderId: string;
fromToken: string;
toToken: string;
fromAmount: string;
toAmount: string;
txHash: string;
}
interface SwapErrorData {
code: string;
message: string;
details?: unknown;
}
interface WalletConnectedData {
address: string;
chainType: string;
}
interface AmountChangedData {
amount: string;
direction: 'from' | 'to';
}

Override any theme color via config or at runtime. Named keys map to internal CSS variables:

KeyCSS VariableDescription
primary--tf-accentButtons, links, active states
background--tf-bgMain background
textPrimary--tf-textPrimary text color
textSecondary--tf-text-secondaryLabels, hints
border--tf-borderBorders, dividers
success--tf-successSuccess states
error--tf-errorError states
warning--tf-warningWarning states

See Theming & Custom Colors for the full CSS variable list and examples.


Three formats are accepted anywhere a TokenIdentifier is expected:

FormatExample
Object literal{ chainId: 1, address: '0xA0b8...' }
CAIP-10 string'eip155:1:0xA0b8...'
JSON string'{"chainId":1,"address":"0xA0b8..."}'

Use the zero address for native tokens:

  • EVM: 0x0000000000000000000000000000000000000000
  • Solana: 11111111111111111111111111111111

See Token Preselection for full details on supported chains and examples.