Webhooks
Mercury can deliver real-time contract event notifications to your HTTP endpoint via webhooks. When an event matches your webhook's filters, Mercury sends a POST request with the event data, signed with HMAC-SHA256 for authenticity.
Creating a webhook
contract_ids accepts one or more contract IDs. Mercury creates one webhook subscription per contract ID and returns all assigned IDs in the response.
curl https://mainnet.mercurydata.app/rest/webhooks/new \
-H 'Authorization: Bearer <your-jwt>' \
-H 'Content-Type: application/json' \
-d '{
"webhook_endpoint": "https://your-endpoint.com/webhook",
"contract_ids": ["CDVNV4...", "CDDNV3..."]
}'Response:
{
"ids": [42, 43],
"secret": "whsec_a1b2c3d4e5f6..."
}Save the secret -- it's shown only once. Use it to verify incoming webhook signatures.
Supplying your own secret
By default Mercury generates a random HMAC secret. You can supply your own by passing webhook_secret:
The provided value is used as-is and returned in the secret field of the response.
Topic filtering
By default, a webhook fires for all events from the specified contract. To filter by specific event topics, pass topic1 through topic4 as XDR base64-encoded values:
Filtering rules:
Each topic filter is optional. Omitted topics act as wildcards (match anything).
All specified topics use AND logic — every filter must match for the event to trigger delivery.
You can filter on any combination: just topic1, just topic3, both topic1 and topic4, etc.
Topic values must match exactly (XDR base64 encoding of the ScVal).
Listing webhooks
Response:
Deleting a webhook
Webhook payload
When an event matches, Mercury sends a POST request to your endpoint:
Headers
X-Mercury-Signature: HMAC-SHA256 hex signature of the request body
X-Mercury-Timestamp: Unix timestamp (seconds) when the request was sent
Content-Type: application/json
Verifying signatures
Optionally use your webhook secret to verify that requests are authentic:
Node.js
Python
Last updated