Ethereum-Solidity Quiz Q9: What is a flashloan?
Source: Dev.to
What is a flashloan?
A flashloan is an uncollateralized loan that exists only during a single blockchain transaction. The borrowed amount must be repaid by the end of the same blockchain transaction.
How flashloans work
- You request to borrow a large amount of tokens.
- The protocol instantly sends you those tokens.
- Do something with the borrowed amount (arbitrage, liquidation, etc.).
- Before the transaction ends, you must repay the loan plus a small fee.
- If you don’t repay by the end of the transaction, the entire transaction reverts (fails) as if nothing happened.
Why it’s possible
Smart contracts can execute complex logic within a single transaction. If any step fails, the entire transaction rolls back. This allows the protocol to safely lend massive amounts because it knows the loan will either be repaid or the whole operation will be undone.