Skip to main content
Widget Light provides a typed event system that lets you react to user interactions, route execution progress, wallet changes, and more. Events are forwarded from the widget iframe to your host application via postMessage.

Subscribing to Events

Use the useWidgetLightEvents() hook to get the event emitter, then subscribe with on and unsubscribe with off:

Key Details

  • Module-level singleton — the event bus is a module-level singleton, so useWidgetLightEvents() can be called from any component. It does not need to be co-located with <LiFiWidgetLight> and does not require any provider wrapping.
  • Subscription-tracked forwarding — events are only forwarded from the iframe when at least one host-side listener is subscribed. When you call events.on(eventName, handler), the host sends a WIDGET_EVENT_SUBSCRIBE message to the iframe. When the last listener for an event is removed, the host sends WIDGET_EVENT_UNSUBSCRIBE. This avoids unnecessary postMessage traffic.
  • Stable reference — the emitter returned by useWidgetLightEvents() is a stable module-level object. You do not need to memoize it or add it to dependency arrays (though it is safe to do so).

Tracking Route Execution

A common use case is tracking the lifecycle of a swap or bridge route:

Event Reference

Route Execution Events

Form and Selection Events

Wallet Events

UI Events

Settings and Preferences Events

Payload Types

All payload types are exported from @lifi/widget-light:
Route-carrying payloads (WidgetLightRouteExecutionUpdate, WidgetLightRouteSelected) use unknown for the route field because the full route type from @lifi/sdk is not available in Widget Light’s zero-dependency type system. Cast to your local @lifi/sdk types if you need typed access to route properties.

WidgetLightEvent Enum

All event names are available as the WidgetLightEvent enum: