0

I'm trying to understand flash loans. It seems like because the to/from payment both happen within the same function, we cannot atomize each to a transaction on chain. Is this assumption incorrect?

1 Answer 1

0

You are correct. Basically, how flash loans work is:

  1. First you call a contract's borrow function.
  2. Then the contract sends the required funds.
  3. After you receive your funds you can do whatever you want with them.
  4. At the end the contract checks if the returned funds are sufficient.
  5. If they are not the transaction will fail.

This is possible due to the fact that if a require() fails at the end of the function, it will revert all the changes that happened before, so there is no way you could take the funds and not return them.

2
  • Sure, but if the flash loan succeeds, does the chain show contract (100 tokens) -> user and user (100 tokens) -> contract, or does the chain not show either because it happened in one transaction?
    – user122417
    Commented Jun 14, 2023 at 20:25
  • As the chain I suppose you mean Etherscan? Block explorers use events to figure out where the tokens went. So both transactions will trigger an event and will consequentially be displayed in transaction. Example: etherscan.io/tx/…
    – Nal Luksic
    Commented Jun 15, 2023 at 7:14

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.