How do flash loans work?

What are flash loans? How is it possible to do anything useful with a loan if it has to be paying back by the next block? So first of all a quick explanation: what are flash loans? Flash loans are loans that are atomically repaid. Atomic is a concept in computer science meaning that something happens all at once or not at all. It is indivisible. This implies in a computer science concept, a transaction that cannot go only halfway. It is commonly used in a database terminology but more generally in distributed systems. Really it's about maintaining the state of the system. So a flash loan is an atomic loan meaning that the transaction in which a smart contract lends you money, can generate a series of contract executions, but at the end after all of these contracts (and you can have many nested contracts in for example Ethereum as a platform but other platforms too) after all of the contracts have executed the last effect of that has to be the repayment of the loan. Now because the chain of transactions that involve multiple contract executions in Ethereum is atomic, meaning that if the transaction isn't validated all the way through to the ends including the part that repays the loan it's not valid and none of it happens. Flash loans are atomic; meaning that a smart contract can give you money as long as within the same transaction that you take the money you also give it back. Which of course implies low risk for the flash loan originator because effectively it's repaid within the same transaction or it doesn't happen.

What can you do with flash loans?

Then there are some side effects and problems that occur with that. What can you do that's useful with this? What you can do is you can execute certain types of contracts where you might need temporary collateral in order to do something but because of the way that contract works you're going to get that collateral back very very quickly. So for example some smart contract that involves some kind of surety bond, an insurance bond, that says this will only execute if you put down some funds as collateral in order to prove that you are going to do this securely. And of course, if you can make those funds come back because you executed the contract securely or to the contract specifications rather -- then you can repay your flash loan and therefore you don't need to put up any of your own collateral and it introduces a very interesting degree of flexibility. If you enjoyed this video please subscribe, like, and share. All my work is shared for free so if you want to support it join me on patreon.com/aantonop Thank you!