Basically I am wondering how does it know when the loan is not paid back. I understand this is easy to check but how can it revert the transaction?

For example let's say I borrow 1M USDT, and then I will swap this to ETH on uniswap and then back to USDT on sushiswap for example. In the end I end up 10K USDT short, so then the transaction will revert, right?

But that means my trades on uniswap and sushiswap will revert back as well?

Because without executing my swaps how can it prove that I won't be able to pay it back? There are many factors that can affect this such as someone else doing arbitrage before me where I wouldn't have the same profit anymore, so how can it verify these without executing any transactions.

This is really confusing me.

1 Answer 1


Usually the lender contract executes a callback after lending the requested assets. It is the callback responsibility to pay the loan and fees.

If the callback hasn't returned the loan nor paid the lender fees then the lender contract will revert the call undoing any operations made by the callback.

interface IBorrower {
    function callback() external;

contract Lender {
    function flashLoan(IBorrower borrower, uint256 amount) {
        // Send tokens to borrower
        uint balance = weth.balanceOf(address(this));
        weth.transfer(address(borrower), amount);

        // Execute callback

        // Check loan was returned
        uint returned = weth.balanceOf(address(this));
        require(returned >= balance + FEES, "Callback failed");

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.