Skip to main content
In this guide you’ll set up real-time push notifications for specific Events that occur in your smart contracts. You can then use those events to trigger important functionality in your application.

Prerequisites

Before you begin: Perform the steps below:
  1. Step 1. Configure Your Webhook for Notifications
  2. Step 2. Import Your Smart Contract
  3. Step 3. Create an Event Monitor
  4. Step 4. Fetch Event History

Step 1. Configure Your Webhook for Notifications

To receive notifications from Circle, you must expose a publicly accessible subscriber endpoint on your side. This endpoint should handle POST requests over HTTPS. For more information on setting up a webhook, refer to the Set up a webhook endpoint, and optionally watch the following video about Webhook Configurations.

Customized Webhook Notifications

Customized webhook notifications enable you to listen to a restricted set of notifications. To create a webhook for smart contract events only select Limit to specific events when creating your webhook in the Circle Console, then choose contracts.EventLog.

The Event Log Notification

When a monitored event occurs, the webhook will receive a notification via POST with the body formatted as follows: Notification
JSON

Step 2. Import Your Smart Contract

Before creating an event monitor, import your smart contract into the Contracts system. This ensures the Contracts platform is aware of your contract and can manage event monitors effectively:
javascript
If you attempt to create an event monitor on an un-imported smart contract, you will receive the following error message:
JSON
For more information on importing a contract, see the Import a contract API endpoint.

Step 3. Create an Event Monitor

Event Monitors listen for configured events on the blockchain and trigger notifications to your webhook endpoint when those events occur. Circle will also save all emitted events under that monitor, allowing you to retrieve historical data later. For more details, see Step 4. Fetch Event History.

Finding and Using the Event Signature

An event signature uniquely identifies an event within a smart contract and is derived from the event’s name and parameter types using the keccak-256 hashing function. For readability, event monitors are created using the human-readable event signature, not the hash. For example, the Transfer event in the ERC-20 interface is defined as:
JavaScript
The human-readable event signature is formatted as: ‘Transfer(address,address,uint256)’.
Note: Spaces are not allowed in the event string signature.
Create an event monitor with the following code:
JavaScript
The response will include details about the event monitor:
JSON
If the event signature you are creating a monitor for does not exist, you will receive the following error message:
JSON
Note: Please ensure the event signature exists if you are using an unverified contract as Circle cannot verify event existence for unverified contracts.
After creating an event monitor, you can view, disable, and delete your monitors. For more information, see the Event Monitoring APIs.

Step 4. Fetch Event History

To retrieve historical events that match your monitors, utilize the event history feature. This functionality is essential for doing analytics, auditing, or reconstructing the application state based on past events:
JavaScript
The data returned will mirror the information in your Webhook Logs in the Circle Console:
JSON
Note:Event history for a monitor will always be available; however, the resource will stop being populated once the monitor is deleted.
For more information, see the Event Monitoring APIs and join our Discord - Build on Circle channel.