Skip to content

API Reference

<tokenflight-widget> HTML Attributes

The only supported public custom element. It routes into swap and receive flows based on configuration.

AttributeTypeDefaultRequiredDescription
to-tokenstring--NoDestination token (CAIP-10 or JSON). Pass a JSON array for multi-token selection.
from-tokenstring--NoSource token (CAIP-10 or JSON). In receive mode (trade-type="EXACT_OUTPUT"), used as the default payment token — see Receive-mode behavior.
trade-typestring"EXACT_INPUT"No"EXACT_INPUT" (swap) or "EXACT_OUTPUT" (receive)
amountstring--NoAmount value, interpreted as input or output based on trade-type
recipientstring--NoCustom recipient address
iconstring--NoCustom icon URL for the target token
lock-from-tokenbooleanfalseNoLock the source token selector
lock-to-tokenbooleanfalseNoLock the destination token selector
from-tokensstring--NoJSON array of allowed source tokens
to-tokensstring--NoJSON array of allowed destination tokens
api-endpointstringhttps://api.hyperstream.devNoHyperstream API base URL
themestring"light"No"light", "dark", or "auto"
localestring"en-US"NoDisplay language
title-textstring--NoCustom title text
title-imagestring--NoCustom title image URL
hide-titlebooleanfalseNoHide the top title bar
hide-powered-bybooleanfalseNoHide the footer branding
no-backgroundbooleanfalseNoRemove background color
no-borderbooleanfalseNoRemove border and shadow
csp-noncestring--NoCSP nonce for injected styles

Boolean Attribute Parsing

Boolean HTML attributes accept these string values:

  • Truthy: "" (present), "true", "1", "yes"
  • Falsy: "false", "0", "no"
html
<tokenflight-widget hide-title></tokenflight-widget>
<tokenflight-widget hide-title="true"></tokenflight-widget>
<tokenflight-widget hide-title="1"></tokenflight-widget>
<tokenflight-widget hide-title="yes"></tokenflight-widget>

Imperative API

TokenFlightWidget

Use the imperative class when you need lifecycle control, callbacks, and runtime theme updates.

ts

const widget = new TokenFlightWidget({
  container: '#widget',
  config: {
    toToken: { chainId: 8453, address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' },
    tradeType: 'EXACT_OUTPUT',
    amount: '100',
    theme: 'dark',
    locale: 'en-US',
  },
  walletAdapter: myAdapter,
  callbacks: { ... },
});

Instance Methods

MethodDescription
initialize()Mount the widget to the container. Creates a Shadow DOM root.
destroy()Unmount the widget and clean up the DOM.
setTheme(theme)Change theme at runtime. Accepts "light", "dark", or "auto".
setCustomColors(colors)Apply CSS variable overrides at runtime.
js
widget.initialize();
widget.setTheme('dark');
widget.setCustomColors({ '--tf-primary': '#FF6B00' });
widget.destroy();

WARNING

After initialize(), the widget does not respond to config changes. Destroy and recreate it when configuration changes.

Registration Helpers

registerWidgetElement(options?)

Registers <tokenflight-widget> only.

ts

registerWidgetElement();

registerElements(options?)

Legacy convenience facade. New integrations should prefer registerWidgetElement() to avoid pulling in compatibility registrations.

ts
interface RegisterElementsOptions {
  walletAdapter?: IWalletAdapter;
  callbacks?: Callbacks;
  customColors?: CustomColors;
  apiEndpoint?: string;
  theme?: Theme;
  locale?: SupportedLocale;
}

Programmatic Callbacks on Web Component Elements

js
const widgetEl = document.querySelector('tokenflight-widget');

widgetEl.__walletAdapter = myAdapter;
widgetEl.__callbacks = {
  onSwapSuccess: (data) => console.log('This element completed:', data),
};

Exported Utilities

Amount Conversion

ts

toDisplayAmount('1000000', 6);
toBaseUnits('1', 6);
formatDisplayAmount('1.234567890');

Chain Utilities

ts

isSolanaChain(SOLANA_CHAIN_ID);
isEvmChain(1);
getChainType(1);
isCrossChainSwap(1, SOLANA_CHAIN_ID);

Constants

ExportValueDescription
DEFAULT_API_ENDPOINT"https://api.hyperstream.dev"Default API URL
SOLANA_CHAIN_ID20011000000Internal chain ID for Solana mainnet

Testing

ts

const mock = new MockWalletAdapter();

Cache Management

ts

clearTokenCache();