Sweeping deposit addresses safely
Moving funds out of many deposit addresses into one wallet looks like housekeeping. Done carelessly, it spends more on gas than it moves, or moves money that was never final.
By Nasfam Business engineering,
On this page
Why deposit addresses are swept
A service that gives every customer their own deposit address ends up with funds spread across thousands of addresses. Sweeping moves them into a small number of wallets the business controls, so payouts are paid from one place, fewer keys hold value at any moment, and the balance on chain can be checked against the ledger in a few lookups instead of thousands.
It looks like housekeeping. It is a stream of real transactions that cost real fees, run against funds that are not always final, on addresses anyone in the world can send to. Each of those facts has a failure mode.
Sweep only what is final
A sweep should only ever move a deposit that is final by its chain's rule. Sweep earlier and a reorg can remove the deposit after you have moved it. On a chain that tracks individual coins, the sweep that spent it becomes invalid along with it; on an account-based chain, the sweep may go through anyway, paid from other funds in the address, and your ledger and the chain stop agreeing.
The finality rule for sweeping is the same one you credit by. If a deposit is not yet spendable for the customer, it is not yet movable for you. The finality guide sets out what final means on each chain.
Paying gas on a token-only address
On Ethereum, every transaction pays its fee in the chain's own coin: "Gas fees have to be paid in Ethereum's native currency, ether (ETH)." A deposit address that received only a token, such as a stablecoin, holds no ether and so cannot send the token anywhere. The same is true on every EVM chain with its own coin.
There are three common ways round it, each with a cost.
- Top up, then sweep. Send the address just enough of the native coin for one transfer, then sweep the token. Two transactions per address, and a leftover of native coin that is rarely worth sweeping back.
- Approve once, then pull. ERC-20 tokens define
approve, which "allows_spenderto withdraw from your account multiple times, up to the_valueamount", andtransferFrom, which moves the tokens. The deposit address pays for one approval; after that, a sweeper account pays the gas to pull funds out each time. - Use a contract as the deposit address. A deposit address that is a contract you control can forward funds when called, with the caller paying the gas. It moves the cost and the complexity into code that must itself be correct.
TRON works differently but has the same shape. Every transaction consumes Bandwidth, and smart contract calls, which is what a token transfer is, also consume Energy. Both come from staking TRX; when an account has too little, TRX is burned to cover the cost. A token-only address with no TRX and no delegated resources cannot pay.
Remember that a failed transaction still pays. ethereum.org: "The fee is paid regardless of whether a transaction succeeds or fails." A sweep that reverts costs gas and moves nothing.
Dust, fake tokens and gas griefing
Some deposits cost more to sweep than they are worth. On Bitcoin, fees are charged by transaction size, "Transactions pay fees based on the total byte size of the signed transaction", so a tiny coin can cost more in fees to spend than it holds. Bitcoin Core's default relay policy goes further and treats an output worth less than about a third of what it would cost to spend as non-standard.
Anyone can send to your addresses, and some will do so to cost you money. Sending a small amount of a token to many deposit addresses, so that a naive system tops each one up with gas to sweep it, is a known attack, often called gas griefing. The attacker spends a little; you spend a gas top-up per address.
Tokens add a second trap. The ERC-20 standard says the Transfer event "MUST trigger when tokens are transferred, including zero value transfers", and anyone can deploy a contract that emits Transfer events under a familiar name. A deposit watcher that trusts the event without checking the token contract can be shown deposits that are worthless or that never happened.
- Set a minimum worth sweeping, by value after fees, per asset and per chain. Below it, leave the funds recorded and swept later with the next deposit.
- Recognise tokens by contract address, from a list you maintain, never by name or symbol.
- Never top up gas because a deposit arrived. Top up only for a sweep you have already decided is worth making.
- Ignore zero-value transfers for crediting and sweeping alike.
Batching and timing
On chains that track individual coins, such as Bitcoin, many small deposits can be spent together in one transaction. Fees follow size, so consolidating when fees are low costs less than doing it when they spike. On account-based chains each address usually needs its own transaction, so the saving comes from choosing when to sweep, not from combining addresses.
Timing is a trade between fees and exposure. Sweeping rarely costs less in fees but leaves more value sitting in many addresses. Sweeping constantly keeps addresses near empty but pays for many small transactions and makes fee spikes hurt more. Decide the trade deliberately, write it down, and revisit it when fees change.
A safe sweep, step by step
- Select balances that are final. Only deposits final by the chain's rule, already credited, on recognised assets.
- Keep what is worth sweeping. Drop anything under the minimum, after fees.
- Make sure the fee can be paid. Top up, use an approval, or call the forwarding contract, for the sweeps you have chosen and no others.
- Record the sweep before you broadcast it, with its source, destination, amount, transaction hash and nonce, so a crash or a retry finds it and does not create a second one. The payouts guide explains why a lost transaction is broadcast again as itself, never rebuilt.
- Wait for the sweep to be final, then mark it complete.
- Record it as an internal transfer. Leftover dust stays on record against the address it is in.
A sweep is an internal transfer
A sweep moves money between two wallets of the same business. It is not revenue, not a payout and not a new deposit, and the ledger should say so with an entry of its own kind.
This matters most for the system that watches deposits. When a sweep lands in the destination wallet, or a gas top-up lands on a deposit address, a deposit watcher sees money arriving at an address it knows. If it does not recognise the business's own wallets as the sender, it can credit a customer for the business's own gas, or count the same funds twice. Tell your watcher which transfers are your own, and test that it ignores them.
Sources
Each was read on 12 November 2026. Where a quotation appears in the guide, it is that page's own words.
- ethereum.org: gas and fees. Fees are paid in ether, and a failed transaction still pays.
- ERC-20 token standard (EIP-20).
approve,transferFrom, andTransferevents for zero-value transfers. - TRON: resource model. Bandwidth and Energy, staking, and TRX burned when resources run short.
- Bitcoin developer guide: transactions. Fees by byte size, and the relay policy for outputs too small to spend.
Keep reading
When is a crypto deposit safe to credit?
Confirmations, reorgs, and what each chain's own documentation says to wait for before a deposit is final.
Never pay twice: idempotent payouts
Idempotency keys, why a timeout is not a failure, and reconciling every outcome you could not see.
