Skip to main content

addCoinbaseOnrampOrderEventListener

Adds a listener for Coinbase onramp order events. This function listens for postMessage events from the Coinbase payment iframe, allowing you to track the order status in real-time. This function is designed to be used with createCoinbaseOnrampOrder when displaying the payment flow in an embedded iframe.

Usage

Parameters

Returns

() => void - A function to remove the event listener. Always call this when cleaning up to prevent memory leaks.

Event Names

The following events are emitted by the Coinbase payment iframe: For a complete list of events, see the Coinbase Onramp documentation.

Complete Example

Here’s how to use this function with createCoinbaseOnrampOrder:

Important Notes

  1. Always remove the listener - Call the returned cleanup function when the payment flow ends (success, error, or cancel) and when your component unmounts.
  2. Set up listener after creating order - Add the event listener after calling createCoinbaseOnrampOrder and before displaying the iframe.
  3. Browser only - This function only works in browser environments. It will throw an error if window is not available (e.g., during SSR).
  4. Events come from pay.coinbase.com - The listener only processes events from Coinbase’s payment domain for security.
Last modified on January 26, 2026