How it works
Implementation
Detect incoming deposits
When a deposit arrives, Dfns sends a See webhook signature verification for the implementation of
wallet.blockchainevent.detected event. Filter for incoming transfers:verifyDfnsWebhookSignature.Execute the sweep transfer
From your queue processor, create a transfer from the deposit wallet to your treasury wallet. The transfer
kind must match the deposit type.Gas fees
The deposit wallet needs native tokens to pay gas fees for the sweep transaction. This creates a chicken-and-egg problem: the wallet receives a token deposit, but may not have native tokens for gas. Two options:Option 1: Fee sponsor (recommended)
Use a fee sponsor so the deposit wallet doesn’t need to hold native tokens at all. A single funded fee sponsor wallet pays gas for all your sweep transactions.Option 2: Pre-fund with native tokens
Fund each deposit wallet with a small amount of native tokens when you create it. Top up as needed after sweeps. This works on all networks but requires more operational overhead.Batching sweeps
Instead of sweeping immediately after each deposit, you can batch sweeps on a schedule (e.g., every hour or once daily). This is particularly useful for:- UTXO networks (Bitcoin, Litecoin, Dogecoin) — batching consolidates many small UTXOs and reduces total fees
- High-volume systems — reduces the number of transactions and associated gas costs
executeSweep inline.
Production considerations
- Verify webhook signatures — Confirm events are from Dfns. See signature verification.
- Handle duplicates — Webhooks may be delivered more than once. Use
externalIdfor idempotency and track processed deposits in your database. - Reconciliation — Run periodic reconciliation jobs using wallet history to catch deposits your webhook may have missed.
- Policies — Add policies to control sweep behavior (e.g., velocity limits, amount thresholds). Service accounts should never have approval authority — keep automation and oversight separate.
- Tier-1 networks only — Deposit detection via
wallet.blockchainevent.detectedis only available on Tier-1 networks. For Tier-2 networks, poll wallet history instead.
Related
Webhooks
Setup, verification, and best practices
Creating transfers
Transfer API usage and asset types
Fee sponsors
Sponsor gas fees for your wallets
Payment processing
Deposit detection and compliance
