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
| Parameter | Type | Description |
|---|---|---|
listener | (event: { eventName: string; data: Record<string, unknown> }) => void | Callback function called when an event is received from the Coinbase iframe. |
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
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:| Event Name | Description |
|---|---|
onramp_api.cancel | User cancelled the payment flow. |
onramp_api.commit_success | Payment was authorized successfully. Transaction is being processed. |
onramp_api.commit_error | Payment authorization failed. event.data.errorMessage contains details. |
onramp_api.polling_success | Transaction completed successfully. Crypto has been sent. |
onramp_api.polling_failed | Transaction failed after payment. event.data.errorMessage contains details. |
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