Skip to main content

Install

HTML
The same script serves Sandbox and Live links. Versioned files never change; /embed/v1.js tracks the latest 1.x and can’t be pinned with integrity. Hashes for every version are at /embed/versions.json. To self-host, copy the file into your build; it has no dependencies.

Onstacks.open(target, callbacks)

Opens the widget in a modal window and returns a handle. target is one of:
  • an options object { widgetId, environment, type, asset, chain, currency, amount, wallet, ref, redirect } (see Add the widget). The script builds the link and adds origin, your page’s origin, so the widget can post messages back to it. During local development, host can point the link at a widget running on localhost.
  • a signed link.
ref is the value you passed when opening the widget. Callbacks report what the widget said in the customer’s browser; they’re not proof of payment. See Track payments.

Onstacks.mount(element, target, callbacks)

Same target and callbacks, rendered inline inside element instead of a window. The frame grows with the widget and the page scrolls. Returns { destroy() }, which removes the frame. If the link has already expired, onError runs with expired and nothing is rendered.

Errors

open and mount throw before anything is shown when the call itself is wrong: Problems after the window opens, such as a wrong widget ID or an unlisted website, show inside the widget as a not-found screen; see If it doesn’t work.

Content Security Policy

script-src covers the embed script; your Onstacks.open(...) call needs a nonce or to live in your bundle. The script adds no stylesheets, so a strict style-src is fine.

What the script does

It creates a <dialog> or <iframe> for the link, listens for message events, forwards the ones that pass these checks to your callbacks, and removes everything on close:
  • event.origin is the widget’s origin, and that origin is ramp.onstacks.io or ramp-sandbox.onstacks.io (or localhost in development).
  • event.source is the frame it opened.
  • The data is { source: "onstacks-widget", version: 1, message } and the payload has the documented shape.
It makes no network requests, stores nothing, evaluates nothing and exposes one frozen global, window.Onstacks. The file is served unminified so you can read it.

Messages

If you embed the widget yourself, these are the messages it posts to the parent page, each wrapped as { source: "onstacks-widget", version: 1, message: { type, payload } }. The widget posts only to the website in your settings (or the signed link’s origin).
Open https://ramp-sandbox.onstacks.io/w/<widget-id>?type=offramp&ref=… (or a signed link) in your own iframe with allow="camera; clipboard-write" and apply the same checks before trusting a message:
JavaScript