Borrowing in Aave
This is part 4 of a 4 part series. We’ll use our existing funds to borrow a percentage of what we’ve deposited.
This code is on https://github.com/cryptocamtech/aave-borrow–tutorial. Remember to create your .env with the account and private key.
- For brevity only the changes to deposit.js are shown.
- We’ll be borrowing 5 DAI on variable interest.
const daiAmountinWei = web3.utils.toWei("5", "ether").toString();
const interestRateMode = 2;
const referralCode = "0";
- Send the transaction to Aave (notice the high gas limit).
const lpAddress = await getLendingPoolAddress();
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress);
await lpContract.methods
.borrow(daiAddress, daiAmountinWei, interestRateMode, referralCode)
.send({ from: myAddress,
gasLimit: web3.utils.toHex(600000),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
})
.catch((e) => {throw Error(`Error borrowing from the LendingPool contract: ${e.message}`)});
Now run it.
node borrow.js
When all goes well you should then see the DAI got up by approximately 5:

Now you have an extra 5 DAI to use! Just remember to pay it back 🙂
That concludes this tutorial. Enjoy 🙂