Webhooks
Build highly responsive experiences with Syndicate’s webhook service and skip having to build and maintain a costly indexer. With a single API call you can subscribe to all the transaction status updates associated with your project and get notified of onchain events faster than traditional indexers and APIs. As soon as a transaction is confirmed you can dynamically re-render your application, send a push notification, or kick off a background job. These webhooks are designed with reliability in mind, and reconcile data across both onchain and off-chain sources for accuracy.
Authenticating Syndicate Events
For security, Syndicate webhooks are signed with a unique secret, verifying that the events originate from Syndicate, not an imposter. Each event from Syndicate includes a Syndicate-Signature
header. Authenticate this signature by generating a SHA256 HMAC with your webhook secret and the event payload, then compare this to the Syndicate-Signature header value.
Guarding Against Replay Attacks
Each Syndicate-Signature header contains a timestamp in milliseconds, a crucial element in preventing replay attacks. To enhance security, we strongly advise that you only trust messages with timestamps that are less than 5 minutes old and discard any others.
Example of Syndicate Signature format
Below is an example showcasing the format of a Syndicate-Signature.
Verifying Signatures
Read the Syndicate-Signature header
Retrieve the syndicate-signature
header from the webhook request.
Divide the header string using ,
to separate elements. Further divide each element with = to identify prefix and value pairs. The prefix t
indicates the timestamp in milliseconds, and s
the signature.
Generate the payload
To form the payload
, merge the following elements:
- Get the actual JSON body (your request body). This body will have the following format:
{ data: CallbackInformation, eventType: EventType}
- Attach a
triggeredAt
field with the timestamp of the signature.
The payload
should look like this:
Note: The payload parameters are returned in alphabetical order, which is critical for signature validation. Ensure to maintain this order when generating hashes to avoid validation issues.
Calculating the Expected Signature
Generate an HMAC using the SHA256 hashing algorithm. The signing secret of the endpoint serves as the key, and the payload
string as the message.
Validating Signature Accuracy
Match the signature in the header against the calculated signature. Evaluate the time difference between the current and the received timestamps, checking if it falls within your acceptable range. To counter timing attacks, employ a constant-time string comparison method when matching the expected signature against the received ones.
Rotate secret
Syndicate allows you to rotate your webhook secret at any time. To do so, simply update your webhook secret in the Syndicate dashboard or via API call. This will immediately invalidate the old secret and generate a new one. You can then use the new secret to validate callbacks.
Webhook Events and Payloads
TransactionStatusChange
This event is triggered each time there is an update to a transaction’s status. The event payload includes the following details:
Example of Signature Validation
This code snippet demonstrates how to validate the signature of a webhook request using a Node.js app:
Our system is designed to ensure reliable delivery of webhooks. If the initial attempt to send a webhook fails, the system will automatically retry up to five times. After five unsuccessful attempts, it will cease further retries. The system expects a successful response, specifically an HTTP status code below 300, to confirm that the webhook has been successfully delivered.