Partners with an API key can have every status change of their swaps sent to their server as it happens. Webhooks follow Standard Webhooks, so you can check each one with an off-the-shelf library in your language.

Set up your endpoint

  1. Create an HTTPS endpoint on your server that accepts POST requests.
  2. Email [email protected] with its URL and your partner name.
  3. We’ll send you a signing secret, starting with whsec_. You’ll only receive it once, so store it as carefully as an API key.
From then on, every firm quote made with your API key sends its status changes to that URL.

What Tern sends

Handle a request

  1. Check the signature, as shown below. If it doesn’t verify, reject the request.
  2. Respond with any 2xx status within 10 seconds.
  3. Do any slow work after responding, or add it to a queue. Requests that take too long are retried.

Check the signature

Use a Standard Webhooks library with your secret and the raw request body, exactly as you received it, before parsing the JSON. It checks the signature and rejects a timestamp more than 5 minutes away from now, which stops anyone who captures a request from replaying it later.
Without a library, the signature is v1, followed by the base64 HMAC-SHA256 of {webhook-id}.{webhook-timestamp}.{body}, keyed by the secret’s bytes: the base64 after whsec_, decoded. Compare it in constant time with each signature in the header.

Delivery and retries

  • You may get the same update twice. Tern keeps retrying until you respond with 2xx. Ignore repeats by their webhook-id.
  • Updates arrive in order for each swap. A later update waits while an earlier one is being retried. Different swaps don’t wait for each other.
  • What counts as a failure: any status other than 2xx, no response within 10 seconds, or a redirect.
  • When Tern retries: 10 seconds after a failure, then doubling each time, up to an hour apart. After 15 attempts, about 6.5 hours, the delivery is marked as failed. Once your endpoint is back up, email [email protected] and we’ll resend failed deliveries.
  • Changing your URL takes effect from the next attempt.
  • Rotating your secret: for 24 hours after we rotate it, each request carries two signatures, one per secret, so either one verifies. Switch your endpoint to the new secret within that time.
Webhooks tell you when something changed. For a cross-chain swap, still check the solver’s tokens on chain before revealing the secret: see Cross-chain swaps.