A smart contract implementation of Aave Flash Loans on Ethereum. This project demonstrates how to execute flash loans using Aave's V3 protocol on the Sepolia testnet.
- Execute flash loans using Aave's V3 protocol
- Check token balances
- Withdraw tokens from the contract
- Built with Hardhat for easy testing and deployment
- Node.js (v14+ recommended)
- npm or yarn
- An Ethereum wallet with Sepolia ETH
- Sepolia RPC URL (from Infura, Alchemy, etc.)
- Clone the repository:
git clone https://github.com/alimirash/FlashLoan.git
cd FlashLoan- Install dependencies:
npm install- Configure environment variables:
cp .env.example .env- Update the
.envfile with your:PRIVATE_KEY- Your Ethereum wallet private keySEPOLIA_URL- Your Sepolia RPC endpoint- After deployment, add your
CONTRACT_ADDRESS
Deploy your flash loan contract to the Sepolia testnet:
npx hardhat run scripts/deployFlashLoan.js --network sepoliaAfter successful deployment, copy the contract address and add it to your .env file as CONTRACT_ADDRESS.
To check the USDC balance of your contract:
npx hardhat run test/getBalance.js --network sepoliaExample output:
Fetching balance of token $USDC for FlashLoan contract ...
The balance is: 499800000 tokens
To execute a flash loan:
npx hardhat run test/requestFlashLoan.js --network sepoliaExample output:
$USDC Before FlashLoan : 499800000
Transaction Hash: 0x682b8bcf678abc40f5c49791dd4d2b156d509c0deb889ac76775a4f21fa5221f
FlashLoan executed in block 8282603
$USDC After FlashLoan : 499700000
The FlashLoan contract is built on Aave's FlashLoanSimpleReceiverBase and implements:
- executeOperation: Logic to execute during the flash loan
- requestFlashloan: Function to request a flash loan from Aave
- getBalance: Check token balances in the contract
- withdraw: Allow the owner to withdraw tokens from the contract
| Script | Description |
|---|---|
getBalance.js |
Check the balance of USDC tokens in the contract |
requestFlashLoan.js |
Execute a flash loan of USDC tokens |
You can obtain test USDC tokens from:
This project is licensed under the MIT License.
- Aave Protocol for the flash loan functionality
- Hardhat for the Ethereum development environment