Skip to content

Why Must Flash Swaps Be Repaid In One Transaction?

If you are used to a centralised exchange, a flash swap may seem like a loan you can repay later; it must be repaid before its blockchain transaction ends because the pool checks its balance before letting that transaction succeed.

What Is A Flash Swap?

A flash swap lets a program take tokens from a trading pool, use them, and return the required value within one transaction. A transaction is one bundled set of instructions sent to the network. Unlike a regular loan, it has no later repayment date.

On a centralised exchange, the exchange holds your balance and can record a debt. A decentralized exchange (DEX) uses smart contracts—programs that run on the blockchain—to manage tokens held in pools. The pool cannot rely on a promise to pay tomorrow. It can only check what happened before the current transaction finishes.

How Does The Same-Transaction Check Work?

The pool sends tokens to a contract and then calls that contract back. A callback is a function the pool triggers so the contract can perform its planned steps, such as trading elsewhere or repaying the pool. At the end, the pool checks its token balances against its trading rules.

Ethereum transactions are atomic: they either complete as a whole or are rolled back as a whole. The Uniswap V2 documentation describes this pattern: if the pool has not received enough by the end, the transaction reverts. A revert undoes its token transfers and contract actions, though the sender still pays gas—the network cost for processing the transaction.

This also explains an edge case: the borrowed tokens do not always have to be returned in the same form. A contract may repay with another token if the pool’s rules and final balances allow it. The pool cares about the required value and balance conditions, not a verbal promise or a later payment.

What Does Repayment Cost In A Simple Example?

Suppose a pool lends 1,000 USDC in a V2-style example with a 0.3% swap fee. If repaying in USDC, the amount needed is about 1,003.01 USDC. The calculation is 1,000 ÷ 0.997; the small difference from simply adding 0.3% comes from how the fee is applied to the repayment amount.

That 0.3% is an illustrative figure for this example, not a promise about any particular pool. Actual fees depend on the protocol and pool. A contract must also cover the network gas cost. For a trade to make sense, its result must cover repayment, fees, and gas, with enough left over to justify the risk of a failed attempt.

Can You Use One From Your Wallet?

A normal wallet address cannot usually handle the pool’s callback by itself. A smart contract must receive the tokens, carry out the steps, and repay within the same transaction. That makes flash swaps a tool for people building or using contract-based strategies, rather than a standard wallet swap with extra time to pay.

Before relying on this mechanism, check that the specific pool supports it and understand its fee and repayment rules. DEX designs differ, so a flash-swap example from one protocol may not apply to another. BaseSwap is a DEX on Base for swapping tokens and supplying liquidity; it is one route to explore ordinary DEX activity on that network, but check the relevant pool’s design before assuming it supports flash swaps. The practical tip: calculate repayment and gas first, then submit only if the expected proceeds cover both.