Making a Flash Loan with Solidity (Aave, Dy/Dx, Kollateral)

Flash Loans are loans that allow the borrowing of an asset, as long as the borrowed amount (and a fee) is returned before the end of the transaction. Those types of loans enable you to perform actions without using your funds for a really small percentage fee (0.09% at the time of writing on Aave and 0% on Dy/Dx). Flash loans can be used for arbitrage across DEXes, liquidation of positions on protocols like Dy/Dx, and migration of CDPs for example. In this tutorial we’ll different ways you can make a flash loan in a Solidity smart contract. If you’d like to learn more about what can flash loans be used for we recommend reading a few articles like this one, this paper or this one.
Another nice way to get ideas on what to build with flash loans is checking some transactions that are using flash loans and check what they are doing on a block explorer.
Currently available flash loans protocols only offer to borrow one asset per transaction, but if you have ETH it is easy for example easy to get DAI by minting them or even use 1inch aggregator to swap to any other token.
Here are the different protocols you can use to perform a flash loan on the Ethereum blockchain:

Flash loans with Aave
Aave is an Open Source and Non-Custodial protocol to earn interest on deposits & borrow assets. As their documentation is really well made and complete we directly invite you to see their documentation.
👍 Advantages:
- Short and convenient code
- Lot of assets available (ETH, USDC, DAI, MAKER, REP, BAT, TUSD, USDT..)
- ETH is directly provided as Ether
- Awesome documentation and community support
👎 Disadvantages:
- A 0.09% fee