Method: Coinbase::Webhook.create

Defined in:
lib/coinbase/webhook.rb

.create(network_id:, notification_uri:, event_type:, event_filters:) ⇒ Coinbase::Webhook

Creates a new webhook for a specified network.

Examples:

Create a new webhook

webhook = Coinbase::Webhook.create(
  network_id: :ethereum_mainnet,
  notification_uri: 'https://example.com/callback',
  event_type: 'transaction',
  event_filters: [{ 'contract_address' => '0x...', 'from_address' => '0x...', 'to_address' => '0x...' }]
)

Parameters:

  • network_id (String)

    The network ID for which the webhook is created.

  • notification_uri (String)

    The URI where notifications should be sent.

  • event_type (String)

    The type of event for the webhook. Must be one of the following:

    • Coinbase::Webhook::ERC20_TRANSFER_EVENT

    • Coinbase::Webhook::ERC721_TRANSFER_EVENT

  • event_filters (Array<Hash>)

    Filters applied to the events that determine which specific events trigger the webhook. Each filter should be a hash that can include keys like contract_address, from_address, or to_address.

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/coinbase/webhook.rb', line 34

def create(network_id:, notification_uri:, event_type:, event_filters:)
  model = Coinbase.call_api do
    webhooks_api.create_webhook(
      create_webhook_request: {
        network_id: Coinbase.normalize_network(network_id),
        notification_uri: notification_uri,
        event_type: event_type,
        event_filters: event_filters
      }
    )
  end

  new(model)
end