Crypto deposit webhooks: signatures, confirmations and retries
Handle crypto deposit webhooks right: verify the HMAC-SHA256 signature, dedupe by event id, credit on confirmation. Node.js and Python code.
A webhook is the cheapest way to learn that coins arrived: instead of polling every address, your server is called when something happens. It is also the easiest place to lose money. An unverified endpoint can be fed fake deposits, a retried delivery can credit a user twice, and crediting too early can credit coins that a chain reorganisation later takes back. This guide covers each of these with the events kryptr.io sends.
The events
| Event | When |
|---|---|
deposit.detected |
an incoming transfer to a wallet appeared on chain |
deposit.confirmed |
it reached the network's confirmation count |
deposit.failed |
it failed or was dropped from the chain |
transfer.created |
a transfer you ordered was queued |
transfer.sent |
it was broadcast; tx_hash is set |
transfer.confirmed |
it reached the network's confirmation count |
transfer.failed |
it was rejected, failed on chain or expired |
wallet.created, wallet.deleted |
a wallet was created or soft-deleted |
wallet.mnemonic_exported |
a wallet's seed phrase was exported |
Events go to every webhook endpoint you registered in the dashboard (each signed with that endpoint's own secret) and to the callback_url of the wallet or transfer they belong to (signed with your account's callback secret). Callback URLs must use https and resolve to public addresses.
Each delivery is a POST with a JSON body:
{"id": "…", "type": "deposit.confirmed", "created_at": "2026-11-30T10:24:31Z", "data": { … }}
and three headers:
X-CryptoEqu-Event: the event type;X-CryptoEqu-Timestamp: the RFC 3339 time of this delivery attempt;X-CryptoEqu-Signature: hexHMAC-SHA256(secret, "<timestamp>.<body>").
Step 1: verify the signature over the raw body
Compute the HMAC over the exact bytes you received, not over a re-serialised JSON object: parsing and printing JSON again can reorder keys or change number formats, and the signature will not match. Compare in constant time.
Node.js (Express):
import express from "express";
import { createHmac, timingSafeEqual } from "node:crypto";
const app = express();
const SECRET = process.env.KRYPTR_WEBHOOK_SECRET;
app.post("/kryptr/webhook", express.raw({ type: "application/json" }), (req, res) => {
const ts = req.get("X-CryptoEqu-Timestamp") ?? "";
const sig = req.get("X-CryptoEqu-Signature") ?? "";
const expected = createHmac("sha256", SECRET).update(`${ts}.`).update(req.body).digest("hex");
const valid = sig.length === expected.length && timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
const fresh = Math.abs(Date.now() - Date.parse(ts)) < 5 * 60 * 1000;
if (!valid || !fresh) return res.sendStatus(401);
const event = JSON.parse(req.body.toString("utf8"));
handle(event); // see step 3
res.sendStatus(200);
});
Python (Flask):
import hmac, hashlib, json, os
from datetime import datetime, timezone
from flask import Flask, request, abort
app = Flask(__name__)
SECRET = os.environ["KRYPTR_WEBHOOK_SECRET"].encode()
@app.post("/kryptr/webhook")
def webhook():
ts = request.headers.get("X-CryptoEqu-Timestamp", "")
sig = request.headers.get("X-CryptoEqu-Signature", "")
expected = hmac.new(SECRET, ts.encode() + b"." + request.get_data(), hashlib.sha256).hexdigest()
if not hmac.compare_digest(sig, expected):
abort(401)
sent = datetime.fromisoformat(ts.replace("Z", "+00:00"))
if abs((datetime.now(timezone.utc) - sent).total_seconds()) > 300:
abort(401)
handle(json.loads(request.get_data()))
return "", 200
Step 2: reject stale deliveries
The timestamp is part of the signed string, so it cannot be changed without breaking the signature. Rejecting deliveries older than a few minutes stops an attacker who captured one valid request from replaying it later. Retries are not affected: every attempt is signed again with a fresh timestamp.
Step 3: deduplicate, then act
If your endpoint does not answer 2xx in time, kryptr retries the delivery with exponential backoff, up to 12 attempts. A slow response that your server did process will therefore arrive again. Two ids protect you:
- the event id (
id) stays the same across retries of one event; - the deposit id (
data.id) stays the same acrossdeposit.detectedanddeposit.confirmed.
Credit a deposit at most once with a unique constraint on the deposit id:
CREATE TABLE credited_deposits (
deposit_id uuid PRIMARY KEY,
user_id text NOT NULL,
asset_id text NOT NULL,
amount numeric NOT NULL,
credited_at timestamptz NOT NULL DEFAULT now()
);
-- In one transaction: INSERT … ON CONFLICT DO NOTHING; credit the balance only if a row was inserted.
Answer 200 quickly and do slow work in a queue; a handler that takes too long is retried even though it succeeded.
Step 4: credit on confirmation, not on detection
A transaction that has just appeared can still disappear: a block can be replaced, or a transaction can fail. Each network has a depth after which kryptr treats a deposit as final:
| Network | Confirmations |
|---|---|
| Ethereum | 12 |
| BNB Smart Chain | 15 |
| Polygon | 20 |
| Arbitrum One | 40 |
| Optimism | 10 |
| Base | 10 |
| Avalanche C-Chain | 3 |
| TRON | 19 (solidified) |
| Bitcoin | 2 |
| Litecoin | 6 |
| TON | 1 |
Use deposit.detected to show "incoming" in your interface and deposit.confirmed to credit. On deposit.failed, show the deposit as failed and credit nothing.
Amounts are decimal strings in whole units ("50", "0.015"). Parse them with a decimal type, never a binary float.
Step 5: reconcile
Webhooks are a notification channel, not the source of truth. After an outage longer than the retry window, or simply once a day, compare your records with the API:
GET /api/v1/wallets/{id}/depositslists a wallet's incoming transfers with their status;- the dashboard's webhook delivery log shows each delivery's attempts, last HTTP status and error.
A reconciliation loop that credits only confirmed deposits not yet in credited_deposits makes missed events harmless.
Checklist
- Verify
X-CryptoEqu-Signatureover the raw body, in constant time. - Reject timestamps older than 5 minutes.
- Deduplicate by event id and deposit id; credit inside one transaction.
- Credit on
deposit.confirmedonly; checkasset_idandamount. - Answer
2xxfast; queue slow work. - Reconcile against
GET /api/v1/wallets/{id}/deposits.