Skip to content

HTML Attributes

Reference for the <tokenflight-widget> custom element. For the programmatic (class-based) API, see JavaScript API.

<tokenflight-widget> 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
recipient-editablebooleanfalseNoAllow the user to edit the recipient address in the UI
refund-tostring--NoAddress to refund failed swaps to (defaults to sender)
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
methodsstring'["crypto"]'NoJSON array of payment methods to enable, e.g. '["crypto","card"]'
default-pay-methodstring--No"crypto" or "card" — in EXACT_INPUT swap mode, skip the method picker and open this tab first
fiat-currencystring--NoDefault fiat currency for card payments (e.g. "USD")
api-endpointstringhttps://api.hyperstream.devNoHyperstream API base URL
fiat-api-endpointstringhttps://fiat.hyperstream.dev when omittedNoOverride URL for the fiat on-ramp API
rpc-overridesstring--NoJSON object mapping decimal chain IDs to custom RPC URLs
referrerstring--NoReferrer address for fee attribution; use with referrer-fee-bps
referrer-fee-bpsstring / number--NoReferrer fee in basis points; use with referrer
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
hide-providerbooleanfalseNoHide the provider name in order tracking
quote-cardstring"hidden" in EXACT_INPUT, otherwise visibleNo"hidden" or "visible" — controls the inline quote card in swap mode
no-backgroundbooleanfalseNoRemove background color
no-borderbooleanfalseNoRemove border and shadow
csp-noncestring--NoCSP nonce for injected styles

methods vs default-pay-method

These two attributes do different things — you usually need both:

  • methods decides which payment tabs are offered at all.
  • In EXACT_INPUT swap mode, default-pay-method decides which tab is open first when you want to skip the picker.
  • In mixed EXACT_OUTPUT receive/card checkout, the widget opens with the method picker.

Want crypto and card with the card tab active by default?

html
<tokenflight-widget
  methods='["crypto","card"]'
  default-pay-method="card"
/>

The order of items in methods does not decide the default — you must set default-pay-method explicitly.

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: { ... },
});

The effective fiat API default is https://fiat.hyperstream.dev when fiat-api-endpoint and registerWidgetElement({ fiatApiEndpoint }) are both omitted.

Instance Methods

MethodDescription
initialize()Mount the widget to the container. Creates a Shadow DOM root.
destroy()Unmount the widget and clean up widget DOM/resources. Destroy your wallet adapter separately if it exposes destroy().
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() when they want explicit registration without the main package's auto-registration side effect.

ts
interface RegisterElementsOptions {
  walletAdapter?: IWalletAdapter;
  callbacks?: Callbacks;
  customColors?: CustomColors;
  apiEndpoint?: string;
  fiatApiEndpoint?: string;
  theme?: Theme;
  locale?: SupportedLocale;
  textOverrides?: TextOverrides;
  hideTitle?: boolean;
  hidePoweredBy?: boolean;
  hideProvider?: boolean;
  noBackground?: boolean;
  noBorder?: boolean;
  methods?: SwapPayMethod[];
  rpcOverrides?: Record<string, string>;
  supportedChainIds?: number[];
  referrer?: string;
  referrerFeeBps?: number;
}

Set chain filtering on the wallet adapter itself, for example new EthersWalletAdapter(provider, { supportedChainIds: [1, 8453] }). Do not rely on a global supportedChainIds registration default for current widgets.

Programmatic Callbacks on Web Component Elements

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

widgetEl.__walletAdapter = myAdapter;
widgetEl.__callbacks = {
  onDepositSuccess: (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();