I'm wondering how does the contract ensure the borrowed money will be paid back? Can anyone provide an example?

1 Answer 1


it's all done in one function, so you can revert if the money isn't paid back. (e.g. I send you 100 bucks, you do what you want with it, but the txn reverts if it's not back in my hand by the end of the block). Here's the standard:

function flashLoan(
    IERC3156FlashBorrower receiver,
    address token,
    uint256 amount,
    bytes calldata data
) external override returns (bool) {
    require(token == address(this), "FlashMinter: Unsupported currency");

    uint256 fee = flashFee(token, amount);
    _mint(address(receiver), amount);

    bytes32 CALLBACK_SUCCESS = keccak256("ERC3156FlashBorrower.onFlashLoan");
        receiver.onFlashLoan(msg.sender, token, amount, fee, data) == CALLBACK_SUCCESS,
        "FlashMinter: Callback failed"

    uint256 _allowance = allowance(address(receiver), address(this));
    require(_allowance >= (amount + fee), "FlashMinter: Repay not approved");

    _approve(address(receiver), address(this), _allowance - (amount + fee));
    _burn(address(receiver), amount + fee);


Source: https://soliditydeveloper.com/eip-3156

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.