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

curl https://api.mercurydata.app/webhooks/new \                                                                                                                                  
    -H "Authorization: Bearer <your-jwt>" \                                                                                                                                        
    -H "Content-Type: application/json" \                                                                                                                                          
    -d '{
      "webhook_endpoint": "https://your-endpoint.com/webhook",                                                                                                                     
      "contract_id": "CDVNV4HBU5WBEQO5K7YZW7NULFLHOTYMUMYUGSPAU2QOADZRIJYTYMM6",
    }'

Response:

{
"id": 42,
"secret": "whsec_a1b2c3d4e5f6..."
}

Save the secret — it's shown only once. If desired you'll use it to verify incoming webhook signatures.

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:

curl -X POST https://api.mercurydata.app/webhooks/new \
    -H "Authorization: Bearer <your-jwt>" \
    -H "Content-Type: application/json" \
    -d '{
      "webhook_endpoint": "https://your-endpoint.com/webhook",
      "contract_id": "CAA3TVCEWVRA426A4FX2FMFFVORECOIXPV52P7XRHPXCRHNAJ5Q5NYKE",
      "topic1": "AAAADwAAAAhwdXJjaGFzZQ==",
      "topic2": "AAAAEgAAAAAAAAAAYK5vRsE..."
    }'

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