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 withcreateCoinbaseOnrampOrder:
Important Notes
- Always remove the listener - Call the returned cleanup function when the payment flow ends (success, error, or cancel) and when your component unmounts.
-
Set up listener after creating order - Add the event listener after calling
createCoinbaseOnrampOrderand before displaying the iframe. -
Browser only - This function only works in browser environments. It will throw an error if
windowis not available (e.g., during SSR). -
Events come from
pay.coinbase.com- The listener only processes events from Coinbase’s payment domain for security.
Related functions
- createCoinbaseOnrampOrder - Create an order to display in an iframe
- getMissingVerificationForCoinbaseOnrampOrder - Check verification requirements