Why Use Avalanche Platform Webhooks?
Avalanche Platform Webhooks enable developers to monitor activities on the P and X chains with the following advantages:- Real-time notifications: Receive updates as events occur.
- Reduced overhead: Eliminate the need for constant blockchain polling.
- Customizable monitoring: Subscribe to specific events and apply filters tailored to your needs.
- Support for multiple sub-events: Track related activities within a single webhook subscription.
Understanding webhook event types
Avalanche Platform Webhooks support two main event types, each with specific sub-events you can subscribe to:- Primary Network Address activity: Tracks balance-related changes and reward distributions for P/X chain addresses.
- Validator activity: Monitors validator registration, balance updates, and reward distributions.
Setting Up a Webhook
To get started, you’ll use the Data API to create your webhook. Authentication is required, so you’ll need an API key.Create Your Request
Here’s how to set up a webhook using curl:Creating a Webhook: Examples
Example 1: Tracking Address Activity
This webhook monitors balance changes, thresholds, and rewards for a specific address on the P-Chain.url
: Where notifications will be sent.chainId
: The chain to monitor (“p-chain” or “x-chain”).eventType
: Set to “platform_address_activity”.network
: “fuji” (testnet) or “mainnet”.metadata.keys
: The address(es) you’re tracking.metadata.subEvents
: The sub-events you want to monitor.metadata.balanceThresholdFilter
: Triggers BALANCE_THRESHOLD if the “unlockedUnstaked” balance falls below 5.5 AVAX (5,500,000,000 nAVAX).
Example 2: Tracking Validator Activity
This webhook monitors a validator’s NodeID for various events.metadata.keyType
: Set tonodeId
orsubnetId
.metadata.keys
: TheNodeID
to track (only one key allowed).metadata.subnetIds
: Filters events to a specific subnet (optional).metadata.l1ValidatorFeeBalanceThreshold
: Triggers if the L1 validator’s balance drops below 5 AVAX.