Skip to content

setupOnrampEventListeners

The setupOnrampEventListeners utility sets up event listeners for the Coinbase Onramp widget. It helps you handle various events like successful purchases, exits, and other user interactions.

Usage

code
import { setupOnrampEventListeners } from '@coinbase/onchainkit/fund';
import type { SuccessEventData, OnrampError, EventMetadata } from '@coinbase/onchainkit/fund';
Module '"@coinbase/onchainkit/fund"' has no exported member 'SuccessEventData'.
const unsubscribe = setupOnrampEventListeners({ onSuccess: (data: SuccessEventData) => { console.log('Purchase successful:', data); }, onExit: (error: OnrampError) => { if (error) { console.error('Exit with error:', error); } }, onEvent: (event: EventMetadata) => { console.log('Event received:', event); }, }); // Clean up when done unsubscribe();

Parameters

{
  host?: string;                                   // Optional custom host URL
  onSuccess?: (data?: SuccessEventData) => void;  // Success callback
  onExit?: (error?: OnrampError) => void;         // Exit callback
  onEvent?: (event: EventMetadata) => void;       // General event callback
}

Returns

() => void - Returns an unsubscribe function that removes the event listeners when called.

Event Types

See the following type definitions for event data: