Aave, previously known as ETHLender, has catapulted to the forefront of the DeFi space. Aave was the first in the space to come up with the idea of a Flash Loan. This is a quick tutorial to build and deploys a smart contract for Flash Loan.

This post was originally published in QuickNode.


Before flash loans, you would have to stake an over-collateralized asset to loan another asset. For example, if I wanted to borrow one DAI I would have to deposit another cryptocurrency that exceeded that value. In other words, you had to have money to borrow money. Flash Loans demolished this idea. And they opened up doors for a new loaning system. They did this by allowing users to borrow without putting up anything as collateral. In this tutorial you will learn how this is possible and how you can do it yourself!

About Aave

Taken from the Aave website.

Aave is a decentralised non-custodial liquidity market protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an over collateralized (perpetually) or undercollateralized (one-block liquidity) fashion.

While that is entirely correct, it may not make much sense to you if you aren’t already familiar with all of the DeFi industry jargon. You could think of Aave as being a decentralized pseudo-bank. Instead of a central bank that validates all of the transactions, Aave has smart contracts that do all of this work in an automated fashion. Depositors put their tokens into Aave, and begin earning interest on their deposit. Borrowers on the other hand will do the opposite. They will take money out of Aave and will begin accruing interest on the amount borrowed. In order to do this, they must be overcollateralized.
There is another method for those that don’t want to deposit money into Aave, and just want to borrow. This is the Flash Loan we mentioned earlier.

About Flash Loans

The previously mentioned Flash Loan is a new way of borrowing assets on the blockchain. Initially implemented by Aave, other trending DeFi protocols such as dYdX quickly followed suit in adding this new feature. There is a property that all Ethereum transactions share that enable Flash Loans to be possible. And this key feature is atomicity.


A transaction is atomic whenever the series of its operations are indivisible and irreducible. Or in plain english— either all or none of the transaction occurs. No halfsies! The Flash Loan leverages atomicity to allow a user to borrow without posting collateral.There are two caveats to mention. First of all, whenever you borrow an asset in a Flash Loan you have to pay a fee of 0.09% of the amount loaned. Secondly, you must pay back the loan in the same transaction in which you borrowed. While this ability is great, it is somewhat limited in its use. Flash Loans are primarily used for arbitrage between assets.

Remix Setup

For the sake of simplicity, we will be using the Remix IDE.

This is a browser-based IDE. Also known as an Integrated Development Environment.Remix comes with the ability to write, debug, deploy, and otherwise manipulate Ethereum Smart Contracts.

When you load up Remix in your browser, you will be greeted by this menu.

We won’t be doing a deep dive on the IDE, as the focus of this tutorial is on the Flash Loan. However, you will want to become familiar with the four sections highlighted: main panel, side panel, icon panel, and terminal.

Before we start writing our smart contracts we will want to download a browser extension that allows us to interface with the Ethereum blockchain. There are several tools out there that unlock such functionality, but the most popular one is MetaMask.

Creating A Polygon Mumbai Endpoint

We will use QuickNode as a custom RPC in our MetaMask wallet to propagate transactions faster. This doesn’t guarantee faster transaction confirmation but increases the chances of getting the transaction in front of a validator. Sign up for a free QuickNode Polygon Mumbai RPC here.

Copy the HTTPS URL. We will need it in the next step.

MetaMask Setup

A step-by-step breakdown of how to install MetaMask.

  1. You will start by downloading the extension off of the website above.
  2. Click on your newly installed extension and agree to the terms and conditions.
  3. Create a secure password!
  4. Write down the mnemonic seed phrase. This should be in the physical world, and shouldn’t be kept anywhere on your computer.
  5. Add the QuickNode Polygon Mumbai Testnet RPC we got in the previous step to MetaMask as a custom RPC. Learn how to add a custom RPC in MetaMask.
  6. Get some Polygon Mumbai Testnet MATIC; you can use QuickNode Multi-chain Faucet.

If the six steps outlined above are completed, you can start writing your first smart contract!

For the further steps on writing and deploying the smart contract for this app, refer to the original post.

About the author 

Radiostud.io Staff

Showcasing and curating a knowledge base of tech use cases from across the web.

TechForCXO Weekly Newsletter
TechForCXO Weekly Newsletter

TechForCXO - Our Newsletter Delivering Technology Use Case Insights Every Two Weeks

>