Back to Lessons
Lesson 16

Flash Minting (ERC-3156)

+25EFFORT
5 sections
mintBurn()
01
text

A flash loan lets you borrow with no collateral, on the condition that you repay within the SAME transaction. ERC-3156 standardizes flash loans; flash MINTING is the token-native form: the token mints you any amount out of thin air, you use it within one call, and it is burned (plus a fee) before the transaction ends. Nothing backs it but the atomicity of the EVM.

02
code
solidity
1// ERC-3156 lender interface (the token itself):
2function maxFlashLoan(address token) external view returns (uint256);
3function flashFee(address token, uint256 amount) external view returns (uint256);
4function flashLoan(
5 IERC3156FlashBorrower receiver,
6 address token,
7 uint256 amount,
8 bytes calldata data
9) external returns (bool);
10
11// The borrower must implement and return the magic value:
12// keccak256("ERC3156FlashBorrower.onFlashLoan")
03
text

Why is lending unbacked, uncollateralized tokens safe? Atomicity. If the borrower does not return amount + fee (and approve it for the burn) by the end of onFlashLoan, the entire transaction reverts — un-minting everything as if it never happened. Legitimate uses include arbitrage, collateral swaps, and self-liquidation. During the call, the token's effective supply can briefly exceed its normal supply.

04
note
Key Insight

Systemic risk: flash loans let anyone temporarily command enormous capital, which supercharges attacks on systems that read instantaneous state — spot-price oracles and naive vote-counting. This is exactly why governance uses getPastVotes (see ERC20Votes) and protocols use time-weighted (TWAP) oracles instead of spot prices.

05
code
solidity
1function onFlashLoan(address initiator, address token,
2 uint256 amount, uint256 fee, bytes calldata data)
3 external returns (bytes32)
4{
5 // ... do arbitrage / swap with 'amount' ...
6 IERC20(token).approve(msg.sender, amount + fee); // enable repayment
7 return keccak256("ERC3156FlashBorrower.onFlashLoan");
8}
Complete

Connect your wallet to mark this lesson as complete

Earn 25 EFFORT tokens