Skip to content
✈️ TokenFlight SDK

Receive Widget

The Receive widget lets users purchase a fixed amount of a specific token. Configure the target token and amount, and the widget handles chain selection and payment routing.

Receive Widget
import { TokenFlightReceive } from '@tokenflight/swap';
const receive = new TokenFlightReceive({
container: '#receive-widget',
config: {
target: {
chainId: 8453,
address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
},
amount: '100',
theme: 'dark',
locale: 'en-US',
slippage: 50,
},
callbacks: {
onSwapSuccess: (data) => console.log('Purchase success:', data),
onSwapError: (data) => console.log('Purchase error:', data),
},
});
receive.initialize();
<tokenflight-receive
theme="dark"
locale="en-US"
default-slippage="50"
target="eip155:8453:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
amount="100"
></tokenflight-receive>
AttributeDefaultDescription
targetRequired. Target token in CAIP-10 format (e.g. eip155:8453:0x...) or JSON
amountRequired. Fixed amount the user will receive
theme'light''light', 'dark', or 'auto'
locale'en-US'Display locale
default-slippage'50'Slippage tolerance in basis points (50 = 0.5%)
from-tokenSource token in CAIP-10 format
iconCustom icon URL for the target token
api-endpointCustom API endpoint URL
csp-nonceNonce for CSP-restricted environments
PropertyTypeDefaultDescription
targetTokenIdentifierRequired. Target token ({ chainId, address } or CAIP-10 string)
amountstringRequired. Fixed amount the user will receive
theme'dark' | 'light' | 'auto''light'Widget color theme
localestring'en-US'Display locale
slippagenumber50Slippage tolerance in basis points
fromTokenTokenIdentifierSource token to pay with
iconstringCustom icon URL for the target token
apiEndpointstringCustom API endpoint URL
customColorsRecord<string, string>CSS color variable overrides
CallbackPayloadDescription
onSwapSuccessSwapSuccessDataFired after a successful purchase
onSwapErrorSwapErrorDataFired when a purchase fails
onQuoteReceivedQuoteResponseFired when a new price quote is fetched
onAmountChangedAmountChangedDataFired when the user changes the payment amount
onWalletConnectedWalletConnectedDataFired when a wallet connects
// Update theme without re-initialization
receive.setTheme('light'); // 'light' | 'dark' | 'auto'
// Apply custom color overrides
receive.setCustomColors({ primary: '#ff6600', background: '#1a1a2e' });
// Clean up the widget
receive.destroy();