Partners with an API key can have every status change of their swaps sent to their server as it happens. Each request is signed, so you can be sure it came from Tern.

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 match, 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

tern-signature looks like t=<unix time>,v1=<signature>.
  1. Split it on , and read t and v1.
  2. Join t, a ., and the raw request body exactly as you received it, before parsing the JSON.
  3. Compute the HMAC-SHA256 of that string using your signing secret, as lowercase hex.
  4. Compare it with v1 using a constant-time comparison. Reject the request if they differ, or if t is more than 5 minutes away from now.
The 5-minute window stops anyone who captures a request from replaying it later.

Delivery and retries

  • You may get the same update twice. Tern keeps retrying until you respond with 2xx. Ignore repeats by checking the body’s id and status.
  • 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 or secret takes effect from the next attempt. A new secret replaces the old one immediately, so update your endpoint right away.
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.