---
eip: 3156
label: ERC-3156
title: Flash Loans
status: Final
type: Standards Track
category: ERC
created: 2020-11-15
official: https://eips.ethereum.org/EIPS/eip-3156
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-3156.md
canonical: https://eips.huatuo.xyz/eip-3156/
lang: en
tldr: A standard lender/borrower interface for single-asset flash loans, so a contract can borrow tokens uncollateralized within one transaction from any compliant lender.
tags: [defi, flash-loan, erc20, callback, standard]
---

# ERC-3156: Flash Loans

> This ERC provides standard interfaces and processes for single-asset flash loans.

**TL;DR:** A standard lender/borrower interface for single-asset flash loans, so a contract can borrow tokens uncollateralized within one transaction from any compliant lender.

## What problem does it solve?

A **flash loan** lends tokens with no collateral on one condition: they are paid back, plus any fee, before the transaction ends. If not, the whole transaction reverts as if the loan never happened. Flash loans power arbitrage, collateral swaps, self-liquidation and refinancing.

Early lenders each invented their own interface: some pulled repayment, some expected it to be pushed back, some had multi-purpose entry points. Every integration was custom. ERC-3156 defines one interface for lenders and one for borrowers so a borrower contract can work with any compliant lender, including tokens that support "flash minting".

## How it works

There are two roles, linked by a callback.

**Lender** (`IERC3156FlashLender`):

| Function | Behavior |
| --- | --- |
| `maxFlashLoan(token)` | Max amount available; **0** (not revert) for unsupported tokens |
| `flashFee(token, amount)` | Fee for that loan; **reverts** for unsupported tokens |
| `flashLoan(receiver, token, amount, data)` | Runs the loan, returns `true` on success |

**Receiver** (`IERC3156FlashBorrower`):

```solidity
function onFlashLoan(address initiator, address token, uint256 amount, uint256 fee, bytes calldata data)
    external returns (bytes32);
```

The flow inside `flashLoan`:

1. Transfer `amount` of `token` to `receiver`.
2. Call `receiver.onFlashLoan(msg.sender, token, amount, fee, data)`, passing `token`, `amount` and `data` unchanged and `fee == flashFee(token, amount)`.
3. Require the return value to equal `keccak256("ERC3156FlashBorrower.onFlashLoan")`.
4. **Pull** `amount + fee` from the receiver with `transferFrom`, or revert. So the receiver must approve the lender for that amount before returning.

## Sample code

A minimal borrower:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC3156FlashBorrower} from "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol";
import {IERC3156FlashLender} from "@openzeppelin/contracts/interfaces/IERC3156FlashLender.sol";

contract Borrower is IERC3156FlashBorrower {
    bytes32 private constant CALLBACK_SUCCESS = keccak256("ERC3156FlashBorrower.onFlashLoan");
    IERC3156FlashLender public immutable lender;

    constructor(IERC3156FlashLender _lender) { lender = _lender; }

    function borrow(address token, uint256 amount, bytes calldata data) external {
        lender.flashLoan(this, token, amount, data);
    }

    function onFlashLoan(address initiator, address token, uint256 amount, uint256 fee, bytes calldata data)
        external override returns (bytes32)
    {
        require(msg.sender == address(lender), "untrusted lender");
        require(initiator == address(this), "untrusted initiator");

        // ... use `amount` of `token` here (arbitrage, refinance, etc.) using `data` ...

        IERC20(token).approve(address(lender), amount + fee); // lender pulls repayment
        return CALLBACK_SUCCESS;
    }
}
```

## Things to know

- Status is **Final**. OpenZeppelin ships `IERC3156FlashLender`/`IERC3156FlashBorrower` interfaces and an `ERC20FlashMint` extension that makes a token its own flash lender.
- **Never trust callback arguments blindly.** Check that `msg.sender` is a lender you trust and that `initiator` is an address you trust; otherwise someone can call your receiver with fake parameters.
- Lenders must check the magic return value. Without it, a contract or EOA that left a standing approval to the lender could be drained by an attacker initiating a loan on its behalf.
- Flash minting makes huge amounts (up to `2^256 - 1` if uncapped) available to anyone for one transaction. Protocols that read balances, prices or utilization within a transaction must assume an attacker can temporarily hold vast sums.
- The standard covers single-asset loans only; multi-asset lenders expose one loan per token call.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-3156
