Prerequisites
You need a deployed contract to monitor. If you completed the Deploy contracts tutorial, you can continue with that contract. If your contract was deployed elsewhere, import it in Step 3.Step 1. Update your project
If you haven’t already, add run scripts for monitoring contract events to yourpackage.json:
If you completed the Deploy contracts tutorial, your project already has the
required SDKs installed. The npm scripts previously listed work with your
existing setup.
Step 2. Set up your webhook
Event monitors send real-time updates to your webhook endpoint when events happen.- webhook.site
- ngrok
- Visit webhook.site
- Copy your unique webhook URL (for example,
https://webhook.site/your-uuid)
Step 3. Register your webhook in Console
Register your webhook URL in the Developer Console:- Go to Developer Console
- Navigate to Webhooks (left sidebar)
- Click Add a webhook
- Enter your webhook URL (from Step 1) and create the webhook
Register your webhook before creating event monitors. This allows Circle to
send notifications to your endpoint.
Step 4. Import a contract (optional)
If your contract was deployed elsewhere and is not yet available in the Developer Console, import it first. If you deployed a contract using Circle Contracts, including the Deploy contracts tutorial, skip this step. Your contract is already available in the Console.If the contract is already imported, you’ll see an error:
contract already exists. This means the contract is already available in the Console and you
can proceed to create an event monitor.Step 5. Create an event monitor
Event monitors track specific contract events. They send updates to your webhook endpoint. This example monitorsTransfer events:
Step 6. Receive webhook notifications
When events occur, Circle sends updates to your endpoint. Here is what aTransfer event looks like:
notificationType: Always"contracts.eventLog"for event monitor webhooksnotification.eventSignature: The event that was emittednotification.contractAddress: Address of the contract that emitted the eventnotification.blockchain: The blockchain network (for example,ARC-TESTNET)notification.txHash: Transaction hash where the event occurrednotification.userOpHash: User operation hash (for smart contract accounts)notification.blockHash: Hash of the block containing the transactionnotification.blockHeight: Block number where the event occurrednotification.eventSignatureHash: Keccak256 hash of the event signaturenotification.topics: Indexed event parameters (for example,fromandtoaddresses)notification.data: Non-indexed event parameters (for example, token amount)notification.firstConfirmDate: Timestamp when the event was first confirmedtimestamp: Timestamp when the webhook was sentversion: Webhook payload version
Step 7. Retrieve event logs
You can also query event logs with the API. This is useful for past events or if you prefer polling.Webhooks vs Polling: Webhooks send real-time updates (push). Polling needs
periodic API calls (pull). Use webhooks for production and polling for testing
or past queries.
Replace
CONTRACT_ADDRESS with your contract address. You can get this
address when you deploy the contract, or by listing your contracts with
listContracts().You can view, update, and delete event monitors with the Circle Contracts API.
See the API
Reference
for details on managing your monitors.
Summary
After completing this tutorial, you’ve successfully:- Set up webhook endpoints using webhook.site or
ngrok - Registered webhooks in the Developer Console
- Created event monitors for specific contract events
- Received real-time webhook updates for contract events
- Retrieved past event logs with the Circle SDK