Flash Loans

Today I am taking a look at a flash loans, a feature in Decentralized Finance (DeFi) that lets people borrow very large sums of crypto, for very short periods of time.

For the usual disclosure, I am not a financial advisor, I don’t even work in finance at all. My day job is as a telecommunications software engineer. Treat everything you read here as some educational resources and not financial advice.

What Are Flash Loans

A flash loan is a feature that lets a user borrow the entire amount of available crypto in a protocols pool, with no up front collateral needing to be provided, for exactly one Ethereum block. This gives users access to potentially far more funds than they would otherwise be able to use, in order to pull off some interesting things, which we will go over below.

One of the major protocols that helps popularize flash loans is AAVE, which I plan to explore in an article all on it’s own, as it is quite an interesting lending platform by it’s own right, even without looking at just the flash loans aspect.


To understand how flash loans works, it’s important to take a minute to remember exactly what a transaction on a blockchain is. It’s a series of steps that get completed and recorded on the ledger, and they are done in an atomic way. This means that every step within the transaction has to complete successfully, otherwise the entire transaction is rolled back and no changes are made to the states within the ledger.

If you think of a simple transfer transaction, lets say you are sending 200 Ethereum (ETH) to someone else. There is two steps involved, first lowering your balance by the required amount, and then raising the balance of the other person. If something were to happen and only the first step went through, it would leave the system in a weird inconsistent state where there is now a missing balance of 200 Ethereum (ETH) unaccounted for.

Now imagine a more complex transaction with a smart contract that has a lot of steps involved. If something failed in the middle of that, who knows what state things could be left in. As a rule, all transactions on a blockchain are done in an atomic way, so that all steps have to be successful or none of them are allowed to go through.

There are lots of reasons for a step in a transaction to fail. There could be a bug in the code, or some data that was incorrect, or even just running out of gas. It’s important to note that with rolled back transactions, gas prices still need to be paid.

How Flash Loans Works

Now that we remember how transactions work, a flash loan is just a series of steps within a transaction, that start with the borrowing of funds and end with the paying of them back plus a fee. We will go through a couple of examples here and see how they work in action. Let’s assume out fee for using the flash loan feature is 0.1%.


One big use of flash loans is for arbitrage trading between different protocols. Imagine that we have two protocols that both have a pool Dai (DAI) / Tether (USDT). On one of the protocols, the price is 1 DAI per USDT and on the other we have a price of 0.99 DAI per USDT.

We could setup a transaction that first borrows 500,000 DAI. We then have the transaction execute a swap on the second protocol, and get 505, 505.50 USDT. The next step is to swap that USDT for DAI on the first protocol and get 505,505.50 DAI. The final step is to pay back the flash loan, plus the fee, so we put 505,000 DAI back into the flash loan protocol, leaving us with a profit of 505.50 DAI.

This is of course a risky move, not just for all the usual risks involved with Decentralized Finance (DeFi), but you have to worry about being front run by another trader, or a bot that is watching for these opportunities. Bots could even be watching the mempool for pending transactions, and just submit theirs with a higher gas prices to ensure theirs goes through first, so this is a very high risk maneuver.

Collateral Swap

Lets imagine you have borrowed 100,000 Dai (DAI) using Ethereum (ETH) as your collateral, but want to switch to using Tether (USDT) to back the loan instead, because the price of Ethereum (ETH) is being too volatile for your liking. You could pull this off using a flash loan.

First, you would take out the flash loan for 100,000 DAI. Now, you can withdraw the ETH you had staked up for your collateral. Next, you can swap your ETH for some USDT on whatever exchange you are using. Now you can take that USDT and use it as collateral back on the lending platform and use it to get another loan for the 100,000 DAI and repay it, plus the fee, to the flash loan protocol.

This has let you successfully swap what collateral was being used to back your loan, without having to go through the trouble of pulling the funds out of whatever it was you borrowed to put them into in the first place, which may not have even been possible in the first place if you had them locked up in some time locked staking pool or something of that nature.

Other Considerations

There are other things to consider when dealing with flash loans. Gas prices is of course a big consideration, as a transaction with a lot of steps can get very pricey in the transaction costs, so it’s very important to factor these in when deciding to do a flash loan.

Price slippage is another big one, which comes from the difference in price that occurs as the ratio of cryptos in the pair changes, and can be a large factor when dealing with a large transaction through a liquidity pool, something like a large arbitrage trade.

I also only went through two examples of what flash loans can be used for, but really, the sky is the limit with them. You have access to the entire funds of the loan for the single transaction, so you can use it for whatever you want.

There is also a high amount of risk involved with them. It’s generally not too risky to use a flash loan itself to pull off a transaction, they are designed to have to get paid back within the same transaction. But the risk comes from things like getting beat to an arbitrage opportunity, or not factoring in the very high gas prices of the transaction, or just plain ole picking a bad move and then amplifying it by using a huge amount of money.

And of course, there are bad actors out there, and as flash loans are still a relatively new technology, they are still often a very big target of hackers looking to exploit a smart contract and drain a large amount of funds, so if you are thinking of funding one of these pools to earn a cut of the fee, you really need to weigh this consideration before you hand over your hard earned crypto.


Flash loans are a very, very risky thing to do. You really need to ensure you are thinking through all of the steps, and factoring in costs and risk at each step of the transaction, even a simple swap within it, if the price changes between when you see the opportunity and when you get the transaction done, you can very easily lose more than you stood to gain from it.

They are expensive as far as transaction costs go, and really, the best use case I see for them, for us consumer level folks who don’t have millions of dollars in investable assets, is for doing things like collateral swaps, and otherwise helping to manage your portfolio. As far as using it as a way to try and amplify gains, this one falls squarely into the “too risky” camp for me, so if you want my opinion on them, stay away and look for another opportunity.

Socials And Other Links

Find me on social media on Twitter, Facebook, Instagram, Telegram and noise.cash.

If you enjoyed this content, you can check me out every weekday. My posts start at my website, but you can also find them cross posted at Publish0x, LeoFinancial, Hive, and read.cash.

I also post a weekly price update video every Saturday over on my YouTube channel, where I will be discussing the weekly price action for some of the major cryptos. You can also sign up for my newsletter which I send out every Friday with news and whatnot from the crypto space, delivered right to your inbox!

You can also find links to resources such as research and news sites over at this link.

Want some more content right now? Check out some of my previous posts:

Binance Smart Chain (BSC)
Impermanent Loss

A few referral links, in case you are interested in the service, and it also helps me out.

Binance — large centralized exchange — referral link saves you 10% on trading fees
Coinbase — basic crypto exchange — referral link gets you bonus crypto on first deposit
Cointiply — very good crypto faucet and earning site — no bonus for you on this referral unfortunately

Originally Posted On My Website: https://ninjawingnut.xyz/2021/07/15/flash-loans/



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store