Skip to main content
The Onramp widget reports its progress back to your page through a postMessage channel. The kit wraps that channel and surfaces it as strongly typed event subscriptions on the widget controller returned by mountIframe or openWindow.

Events

Every event the widget dispatches has the shape:
TypeScript
  • event is the high-level effect. For example, INITIALIZATION_ERROR indicates that the widget couldn’t start.
  • code narrows the cause. For example, an INITIALIZATION_ERROR with code INVALID_SESSION_TOKEN means the session token was missing or invalid.
  • payload carries event-specific metadata such as amount, tokenSymbol, paymentMethod, orderId, and transactionHash. Errors include errorMessage and a boolean canRetry.
The full list of event types and codes is exported from the App Kit SDK as ONRAMP_EVENT_TYPES and ONRAMP_EVENT_CODES.
The widget controller does not validate event envelopes against a closed schema. A widget release that adds a new event, code, or payload field is delivered to your wildcard handler verbatim instead of being dropped. Known events still get type-safe callbacks for autocomplete.

Event types

INITIALIZATION_ERROR codes

DEPOSIT_NOT_COMPLETED codes

Subscribe with typed callbacks

The simplest way to handle events is to pass callback options to mountIframe or openWindow. Each option corresponds to one event:
TypeScript

Subscribe after the widget is mounted

The widget controller returned by mountIframe and openWindow has on and off methods. Use them when you need to add listeners after construction or manage subscriptions dynamically:
TypeScript

Subscribe to every event

Pass '*' to receive every envelope as it is dispatched. This pattern works well for analytics:
TypeScript
Wildcard subscriptions receive future event types the widget may add, with no SDK upgrade required.

Handle session expiry

A session can expire while the widget is open if the user idles long enough. When that happens, the widget emits DEPOSIT_NOT_COMPLETED with code SESSION_TIMEOUT. The App Kit SDK surfaces this and the INVALID_SESSION_TOKEN initialization error through a dedicated onSessionExpired callback so you do not have to branch on codes by hand:
TypeScript
onSessionExpired fires alongside onDepositNotCompleted or onInitializationError, so existing handlers continue to run. The dedicated callback is your “mint a new session and re-launch” signal.

Close unused widgets

Each mountIframe() call, and each successful openWindow() call, returns a widget controller. Keep that controller and call widget.close() before starting over or when the user leaves the view.
TypeScript
For iframe mode, the kit auto-disposes the widget if the container is removed from the DOM without a close() call. Call widget.close() when you know the widget is no longer needed.

Webhooks remain the source of truth

DEPOSIT_SETTLED is a UX signal, not a deposit completion record. A user can close the tab between DEPOSIT_SUBMITTED and DEPOSIT_SETTLED and never receive the settlement event, even though the deposit succeeds. Use lifecycle events to update the UI; reconcile final deposit state from webhook events delivered to your backend.