Skip to main content

Swap Widget

The Treasures swap widget puts the swap box from swap.treasures.io on your own site. Your users buy and sell tokenized stocks from their own wallets without leaving your page. Every trade is signed in the user's wallet; neither you nor Treasures ever holds their funds or keys.

You need no API key, no backend and no sign-up to embed it. An integrator ID is optional: it credits the trades to your organisation and lets you charge your own fee.

Add it​

Put these two lines where the swap box should appear:

<script src="https://swap.treasures.io/widget/v1.js" async></script>
<treasures-swap integrator="intg_…" stock="AAPL" theme="light"></treasures-swap>

The script defines a <treasures-swap> custom element. The element makes an iframe that shows the widget, sizes it, and passes the widget's events on to your page. Every attribute is optional; Configuration lists them all.

The element is plain HTML, so it works the same in React, Vue, Svelte or a static page. Re-rendering it with the same attribute values does nothing, so a framework that redraws often is safe.

Size​

  • Width: up to 520 px. In a narrower container the box fills its width.
  • Height: the box grows to fit its content, from a minimum of 510 px, which already fits a quote. The page below it moves only when a notice or the quote's details appear.
  • A fixed height: set height (in pixels, at least 510) to keep your layout still. The box then stays that size and scrolls inside when its content is taller.

When a dialog opens (wallet connect, trade review) while the top of the widget is scrolled out of view, the widget scrolls it back into view.

Strict Content Security Policy​

If your site sends a Content Security Policy, allow the loader script and the widget's frame:

frame-src https://swap.treasures.io;
script-src https://swap.treasures.io;

Your page's address​

The widget shows on pages served over https, and on http://localhost or http://127.0.0.1 while you test. On any other plain-http page it stays blank. Passing in your page's own wallet (Connecting Wallets) needs a public https address even in testing: use a tunnel such as cloudflared or ngrok.

What your users see​

  • The Treasures swap box, with a "Powered by Treasures" line. The user accepts Treasures' Terms in the widget before their first trade.
  • Their own wallet, connected in the widget or passed in by your page (see Connecting Wallets). The wallet shows every amount before the user signs.
  • Every fee as its own line before they sign, including yours if you charge one, labelled with your name.
  • A wallet settings menu where they can disconnect a wallet the widget connected.

The widget trades at the same price as swap.treasures.io, plus your fee if you set one. It is not available in every country.

Next​

PageWhat it covers
ConfigurationEvery attribute: the starting stock, side and amount, locks, chain and stock lists, height, and changing them at runtime
Connecting WalletsThe widget's own connect, limiting it to one wallet type, and using the wallet your page already connected
CustomizationTheme, colours, corners, font and shadow
EventsWhat the widget tells your page: trades submitted, filled and failed, wallets connected, bridges in flight
Integrator ID and FeesGetting credit for your users' trades, your own fee, and reporting