Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Installation

Load the STON.fi Widget directly from the CDN or on demand through the npm loader.

You can load the STON.fi Widget from a content delivery network (CDN) using a script tag or the npm loader. A script tag downloads the widget as the browser parses your HTML, without a package installation or bundler. The npm loader downloads the same script when your application calls load(), so you control when the download starts.

The widget implementation is distributed exclusively through the CDN. Only the loader is published as an npm package. Your integration receives updates without requiring you to update dependencies, rebuild your application, or redeploy it.

Both options use a CDN URL with a major version prefix, currently /v0/. Updates within that major version do not introduce breaking changes and take effect on subsequent page loads. Breaking changes use a new prefix, such as /v1/, so you choose when to upgrade.

Ways to install

CDN script

Load the widget from this CDN URL:

https://widget.ston.fi/v0/index.js

The script exposes the widget constructor as window.OmnistonWidget. It also includes the widget styles, so you do not need a separate CSS import.

In this minimal example, the DOMContentLoaded handler creates a widget instance and mounts it into a container. Give your container an id and pass that ID to document.getElementById():

<html>
  <head>
    <script src="https://widget.ston.fi/v0/index.js"></script>
    <script>
      document.addEventListener('DOMContentLoaded', () => {
        const widget = new window.OmnistonWidget({
          tonconnect: {
            type: 'standalone',
            options: {
              manifestUrl: 'https://your-app.com/tonconnect-manifest.json',
            },
          },
        });

        widget.mount(document.getElementById('omniston-widget-container'));
      });
    </script>
  </head>
  <body>
    <div id="omniston-widget-container"></div>
  </body>
</html>

loader package

Use @ston-fi/omniston-widget-loader to control when your application downloads the widget. For example, start the download when a swap screen opens.

Install the loader:

Importing the loader does not download the widget. Call load() explicitly to download the widget for the corresponding major version from the CDN. The returned promise resolves to the widget constructor. The following example creates an instance and mounts it into the same container as the CDN example:

The npm package also includes TypeScript types for the widget API.

Lifecycle

Creating a widget instance prepares its configuration. Call widget.mount() to render it into an existing container, and widget.unmount() to remove the rendered interface.

Mount and unmount

Mount the widget after the container exists in the DOM. Call unmount() before removing the container, such as during component cleanup or a route change. You can reuse the same widget instance by mounting it again after unmounting:

Call unmount() before mounting an instance into another container. Unmounting leaves the container element in the DOM.

Events

Use widget.on(event, callback) to observe lifecycle events. Register a handler before the operation you want to observe:

Event
Callback argument
When it fires

mount

Container element (HTMLElement)

After the widget interface is mounted. Wallet connection and asset loading continue asynchronously.

unmount

None

When widget.unmount() is called.

The mount callback receives the container element directly:

Event subscriptions remain active across remounts. The function returned by on() removes that handler. Call it when you no longer need the subscription:

Next step

See Configuration for TON Connect, asset, and integrator fee options. See Customization for appearance settings.

Last updated