Lesson 13: depositing WETH in Aave through aaveBorrorw.js #2003
-
Hi all, In Why shouldn't we use And, if we're using aaveBorrow.js const {getWeth, AMOUNT} = require("../scripts/getWeth")
const {getNamedAccounts, ethers} = require("hardhat")
async function main() {
await getWeth()
const {deployer} = await getNamedAccounts()
const lendingPool = await getLendingPool(deployer)
const wethTokenAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
await approve(wethTokenAddress, lendingPool.address, AMOUNT, deployer)
console.log("Depositing now...")
await lendingPool.deposit(wethTokenAddress, AMOUNT, deployer, 0)
console.log("Deposited!!")
} getWeth.js const { ethers, getNamedAccounts, network } = require("hardhat")
const { networkConfig } = require("../helper-hardhat-config")
const AMOUNT = ethers.utils.parseEther("0.1")
async function getWeth() {
const { deployer } = await getNamedAccounts()
const iWeth = await ethers.getContractAt(
"IWeth",
networkConfig[network.config.chainId].wethToken,
deployer
)
const txResponse = await iWeth.deposit({
value: AMOUNT,
})
await txResponse.wait(1)
const wethBalance = await iWeth.balanceOf(deployer)
console.log(`Got ${wethBalance.toString()} WETH`)
}
module.exports = { getWeth, AMOUNT } |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hey @ManuWeb3 the |
Beta Was this translation helpful? Give feedback.
-
Hi @othaime-en , thanks for explaining. we only need the amount in wei form not in WETH looks correct as per the documentation link you posted. But then, if it's just the unit await lendingPool.deposit(wethTokenAddress, AMOUNT, deployer, 0)``` I mean to ask: Secondly, if it's just about I'm not able to connect all the dots here. |
Beta Was this translation helpful? Give feedback.
Hey @ManuWeb3 the
getWeth()
function allowed us to programmatically deposit ETH into the WETH contract and get back WETH right? Well... creating the function was a simple demonstration of how to achieve that and it was a good functionality too. However, for us to interact with thedeposit()
function of thelendingPool
contract we only need the amount inwei
form not in WETH. Checkout this section of the documentation to understand it more.So in as much as the
getWeth()
function was really useful, we didn't need it in this scenario.