How do I borrow a flash loan?
Mainnet smart contract addresses are listed in the Smart Contracts guide
This guide demonstrates how to borrow a flash loan from Equalizer Vaults in a few simple steps. For the demo purpose, we deployed a simple Flash Borrower Example smart contract on the Rinkeby Testnet. Do NOT send mainnet tokens to these smart contracts as they will be lost!
Flash Borrower Example doesn't perform any business logic. We invite you to build your own trading logic using Equalizer Flash loans.
For this example you need
Open the Flash Loan Provider Flash loan provider is a smart contract developed by Equalizer that enables you to borrow flash loans. You can inspect on Etherscan the Flash Loan Provider:
Flash Loan Provider Smart Contract
Connect your wallet Connect your wallet by clicking on Connect to Web3 and select one of the supported wallets (in our example, Metamask)
Connect your wallet
A wallet window will open and prompt you to connect with your wallet.
Borrow a flash loan Now you can borrow a flash loan. Click on the flashLoan function so you will be able to enter the function parameters.
flashLoan function
In the table below, we explain the arguments and provide some example inputs you can test. All fields are mandatory.
Argument
Description
Example
receiver
Address of the smart contract that will borrow and return a flash loan.
0x5b4b021d2abcf6116d782884bc5cd414027aeff2 (pre-deployed FlashBorrower Example)
token
The token address we want to borrow. In the example, you can find the USDT test token address.
0xbE6C02195A28d163A1DF2e05B0596416d326b190
amount
Amount of tokens we want to borrow. Note that USDT has 6 decimal places.
100000
data
Input data for the Flash Borrower smart contract.
0x00
Write and View your transaction
Click on Write that will open your wallet and prompt you to sign the transaction. After the transaction is successfully processed, you can inspect the transaction. Example: https://rinkeby.etherscan.io/tx/0xc05e3a4dd0c59aa4de055e8f8f727eaa1f6da1a0c21f2b42fd427a479553b561
Congratulations, you just
  • borrowed 0.1 USDT from the Equalizer Vaults
  • Returned 0.1 USDT with 0.05% fee

Appendix - Flash Borrower Example smart contract

Below we present the Flash Borrower Example smart contract used in the example. The smart contract only borrows and returns funds. Business logic must be provided by the user.
1
// SPDX-License-Identifier: MIT
2
pragma solidity 0.8.4;
3
4
interface IERC20 {
5
function approve(address spender, uint256 amount) external returns (bool);
6
}
7
8
interface IERC3156FlashBorrower {
9
/**
10
* @dev Receive a flash loan.
11
* @param initiator The initiator of the loan.
12
* @param token The loan currency.
13
* @param amount The amount of tokens lent.
14
* @param fee The additional amount of tokens to repay.
15
* @param data Arbitrary data structure, intended to contain user-defined parameters.
16
* @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
17
*/
18
function onFlashLoan(
19
address initiator,
20
address token,
21
uint256 amount,
22
uint256 fee,
23
bytes calldata data
24
) external returns (bytes32);
25
}
26
27
/*
28
* FlashBorrowerExample is a simple smart contract that enables
29
* to borrow and returns a flash loan.
30
*/
31
contract FlashBorrowerExample is IERC3156FlashBorrower {
32
uint256 MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
33
34
// @dev ERC-3156 Flash loan callback
35
function onFlashLoan(
36
address initiator,
37
address token,
38
uint256 amount,
39
uint256 fee,
40
bytes calldata data
41
) external override returns (bytes32) {
42
43
// Set the allowance to payback the flash loan
44
IERC20(token).approve(msg.sender, MAX_INT);
45
46
// Build your trading business logic here
47
// e.g., sell on uniswapv2
48
// e.g., buy on uniswapv3
49
50
// Return success to the lender, he will transfer get the funds back if allowance is set accordingly
51
return keccak256('ERC3156FlashBorrower.onFlashLoan');
52
}
53
}
Copied!