AAVE Deposit/Borrowing Tutorial Part IV

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-borrowtutorial. Remember to create your .env with the account and private key.

  1. For brevity only the changes to deposit.js are shown.
  2. We’ll be borrowing 5 DAI on variable interest.
const daiAmountinWei = web3.utils.toWei("5", "ether").toString();
const interestRateMode = 2;
const referralCode = "0";
  1. 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 🙂

Published by Crypto Cam Tech

Professional developer for 30 years + with the passion for helping others in their journey.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: