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
eventis the high-level effect. For example,INITIALIZATION_ERRORindicates that the widget couldn’t start.codenarrows the cause. For example, anINITIALIZATION_ERRORwith codeINVALID_SESSION_TOKENmeans the session token was missing or invalid.payloadcarries event-specific metadata such asamount,tokenSymbol,paymentMethod,orderId, andtransactionHash. Errors includeerrorMessageand a booleancanRetry.
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 tomountIframe
or openWindow. Each option corresponds to one event:
TypeScript
Subscribe after the widget is mounted
The widget controller returned bymountIframe 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
Handle session expiry
A session can expire while the widget is open if the user idles long enough. When that happens, the widget emitsDEPOSIT_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
EachmountIframe() 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
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.