Skip to main content

Embed the Kaia Bridge widget

The widget puts the Kaia Bridge on your website with one iframe. Your users pick chains and tokens, compare every provider's offer, and sign with their own wallet. You don't need a backend or any bridge code.

1. Request a widget key​

Email ecosystem@kaia.io with your project name and every website that will show the widget, as scheme and host, for example https://app.example.com. List each subdomain separately. Kaia sends you:

  • a widget key, kaia_pk_…, and
  • the embed code.

The widget key is public: it's meant to sit in your page's HTML. It works only inside the Kaia widget, only on the websites you listed, and only with your access settings (providers, chains, tokens and rate limit). It can't be used to call the API from anywhere else.

It isn't the same as an API key (kaia_…), which is secret. Never put an API key in a page.

2. Add the iframe​


<iframe
src="https://bridge-aggregator.kaia.io/widget?key=kaia_pk_YOUR_KEY"
title="Kaia Bridge"
style="width: 420px; max-width: 100%; height: 640px; border: 0"
allow="clipboard-write"
></iframe>

Browsers show the widget only on the websites you listed. On any other site, the frame stays empty.

URL parameters​

ParameterRequiredWhat it does
keyYesYour widget key. If it's missing, wrong or turned off, the widget shows "This widget isn't available".
fromChainIdNoThe source chain to start with, for example 1 for Ethereum.
toChainIdNoThe destination chain to start with. Defaults to Kaia (8217).

Widget keys usually keep Kaia on one side of every route; Kaia sets this with your access settings. Then, if a user picks another chain on one side, the other side moves to Kaia, and a URL like ?fromChainId=1&toChainId=56 opens as Ethereum → Kaia. A key without this setting opens the chains in the URL as they are.

3. Let the iframe fit its content (recommended)​

The widget's height changes as users move through it. The easiest way to keep the iframe the right size is the helper script, which creates the iframe and resizes it for you:


<script src="https://bridge-aggregator.kaia.io/widget-helper.js"></script>
<div id="kaia-bridge-widget"></div>
<script>
const widget = KaiaBridgeWidget.init({
container: "#kaia-bridge-widget",
options: { key: "kaia_pk_YOUR_KEY", fromChainId: 1 },
minHeight: 560,
});
// Later: widget.updateOptions({ fromChainId: 56 }); widget.destroy();
</script>

OptionDefaultWhat it does
container(required)The element, or a CSS selector, to put the iframe in.
options(required)The URL parameters above. key is required.
url/widget on the host the script came fromThe widget page. Load the script from the QA host to embed the QA widget.
minHeight560The iframe never gets shorter than this, in pixels.
onMessagenoneCalled with each message from the widget. See Listen for transfer events.

If you'd rather write the iframe yourself, listen for the widget's height messages. The widget sends { type: "widget-resize", height } only to your page. Check that each message comes from the widget before using it:


<iframe id="kaia-bridge" src="https://bridge-aggregator.kaia.io/widget?key=kaia_pk_YOUR_KEY"
title="Kaia Bridge" style="width: 100%; max-width: 480px; height: 640px; border: 0"></iframe>
<script>
const WIDGET_ORIGIN = "https://bridge-aggregator.kaia.io";
const frame = document.getElementById("kaia-bridge");
window.addEventListener("message", (event) => {
if (event.origin !== WIDGET_ORIGIN || event.source !== frame.contentWindow) return;
if (event.data?.type === "widget-resize") frame.style.height = Math.max(event.data.height, 560) + "px";
});
</script>

4. Listen for transfer events (optional)​

The widget also tells your page when a transfer moves forward. Use these messages for your own UI or analytics, for example to show a thank-you note or count completed transfers. Like the resize message, they go only to your page's origin.

MessageWhen it's sent
{ type: "widget-resize", height }The widget's height changed.
{ type: "transfer-sent", kind, adaptorId, fromChainId, toChainId, fromToken, toToken, fromAmount, txHash }The user signed and the transaction was sent. kind is "bridge" or "swap".
{ type: "claim-ready", adaptorId, fromChainId, toChainId, txHash }Wormhole only: the claim can now be made on the destination chain.
{ type: "transfer-complete", kind, adaptorId, fromChainId, toChainId, txHash, toAmount?, destinationTxHash? }The tokens arrived. toAmount and destinationTxHash are included when known.
{ type: "transfer-failed", kind, adaptorId, txHash?, reason }The transfer failed. txHash is missing if nothing was sent. When the provider gave the tokens back, reason is "Refunded by the provider".

adaptorId is the provider, txHash is the source chain transaction, and amounts are strings in the token's smallest unit (for example "1000000" is 1 USDT with 6 decimals).

With the helper script, pass onMessage:


<script>
KaiaBridgeWidget.init({
container: "#kaia-bridge-widget",
options: { key: "kaia_pk_YOUR_KEY" },
onMessage: (msg) => {
if (msg.type === "transfer-complete") console.log("Arrived", msg.adaptorId, msg.txHash, msg.toAmount);
if (msg.type === "transfer-failed") console.log("Failed", msg.reason);
},
});
</script>

With your own iframe, add to the listener above, after the same event.origin and event.source check:


window.addEventListener("message", (event) => {
if (event.origin !== WIDGET_ORIGIN || event.source !== frame.contentWindow) return;
const msg = event.data;
if (msg?.type === "transfer-sent") console.log("Sent", msg.kind, msg.fromAmount, msg.txHash);
if (msg?.type === "transfer-complete") console.log("Arrived", msg.txHash);
});

These messages are a convenience, not proof of payment. If you need to act on a transfer, for example to credit a user, check the transaction hash on the chain. The chain is the source of truth.

What your users see​

  • Bridge: pick the source and destination, enter an amount, and compare every provider's offer. Each offer shows the amount received, the fee and the time. The offer that delivers the most is labelled Best Return, and the quickest is labelled Fastest. The offer that delivers the most is selected by default, and the user can pick another. Then the user signs. The widget asks for any token approval first and follows the transfer until it arrives.

  • Wormhole routes: a Wormhole transfer needs a second transaction, the claim, on the destination chain. The widget says this up front and shows a Claim button when the claim is ready. For the claim, the user needs:

    • a little of the destination chain's native token for gas, for example BNB on BNB Chain (about $0.01 in our test), and
    • that chain added in the wallet. The widget asks the wallet to add it and switch to it, and the user approves this in the wallet.

    Transfers waiting to be claimed stay claimable. The user can come back later, and the widget lists them again.

  • Swaps on Kaia: when both sides are Kaia, the widget swaps between Kaia tokens.

  • Earn: users can deposit USDT on Kaia into SuperEarn. Withdrawals happen on superearn.io. The Earn tab is on by default. To turn it off for your widget key, email ecosystem@kaia.io.

  • Wallets: browser-extension wallets (MetaMask, Rabby, Kaia Wallet and others), and WalletConnect for wallet apps on phones. On a phone with no wallet in the browser, the widget offers Open in MetaMask or Open in Kaia Wallet. Some wallets, Kaia Wallet included, need the destination network added before a claim. The widget asks the wallet to add it, and the user approves that in the wallet.

  • No surprise pop-ups: opening the page never opens the wallet. A returning user whose wallet is unlocked and already approved your site is reconnected quietly.

  • Refunds: if a provider can't complete a transfer, it may send the tokens back to the user's wallet on the source chain. The widget then shows Refunded, with the amount and a link to the refund transaction.

  • Clear outcomes: after the user signs, the widget confirms the transaction through the wallet and through public chain RPCs. If nothing confirms within 10 minutes, it shows "Sent, but not confirmed yet" with an explorer link, instead of inviting a second send.

Security​

  • Only the widget key goes in your pages. Keep any API key on your server.
  • In your own message listener, always check event.origin and event.source, as shown above.
  • Wallet support inside iframes differs between wallets. Before launch, test the wallets your users have on your real domain.
  • To add or remove a website, or to replace a leaked widget key, email ecosystem@kaia.io. A replaced key stops working at once, so update your embed code at the same time.

Troubleshooting​

What you seeLikely cause
An empty frame, and the browser console mentions frame-ancestorsYour page's exact address isn't on your list. Check https:// against http://, www., subdomains and ports. Changes apply within a minute.
An empty frame on an http:// pageOnly QA accepts http://localhost addresses. Production and any other http:// page get the empty frame. See Test on QA.
"This widget isn't available"The key is missing or mistyped, or the widget was turned off for your project.
A chain or token is missingIt isn't in your access settings, or there's no live route to or from Kaia right now.
No offers for an amountThe amount is below the providers' minimums. Each provider has its own minimum, and minimums change. For example, from Kaia our tests saw Rhino.fi quote from about 0.06 USDT, and Layerswap from about 0.2 to 1 USDT depending on the destination. Wormhole has no practical minimum, but the user needs gas to claim. Try a larger amount.
The Claim button isn't showing yetThe claim isn't ready. It takes about a minute from Kaia, BNB Chain or Polygon, and about 20 minutes from Ethereum, Arbitrum or Base. The transfer stays claimable, so the user can come back later.
"Claim failed: could not detect network", or the wallet can't reach the chainThe wallet's network entry for the destination chain isn't responding. Remove the network from the wallet and add it again with a working RPC (for BNB Chain, for example https://bsc-dataseed.binance.org), switch to it, and click Claim again. The transfer stays claimable meanwhile.
The transfer shows RefundedThe provider couldn't complete it and sent the tokens back to the user's wallet on the source chain, minus any network fee. Nothing was lost. The user can try again, for example with another provider's offer.
The claim fails for lack of gasThe wallet has no native token on the destination chain. Add a little, for example some BNB on BNB Chain, and click Claim again.

Test on QA​

Use https://bridge-aggregator-qa.kaia.io/widget?key=… with a QA widget key, or load widget-helper.js from https://bridge-aggregator-qa.kaia.io. QA keys and websites are set up separately from production.

The websites you list must use https://, for example https://app.example.com. For testing on your own computer, QA also accepts http://localhost addresses: ask Kaia to add, for example, http://localhost:3000 to your QA widget's websites. Production never accepts http://.

Make this page better