Lesson 13 - No contract deployed with name IERC20 #1181
-
Can't figure out why my code is not going through. const { getContractFactory } = require("@nomiclabs/hardhat-ethers/types")
const { getNamedAccounts, ethers } = require("hardhat")
const { getWeth, AMOUNT } = require("../scripts/getWeth")
async function main () {
await getWeth()
const { deployer } = await getNamedAccounts()
//abi and address
//Lending pool address provider: 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5
// Lending pool :
const lendingPool = await getLendingPool(deployer)
console.log(`LendingPool address ${lendingPool.address}`)
// deposit
const wethTokenAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
//approve
await approveErc20(wethTokenAddress, lendingPool.address, deployer)
console.log("Depositing....")
await lendingPool.deposit(wethTokenAddress, AMOUNT, deployer, 0)
console.log("Deposited!")
}
async function getLendingPool(account) {
const lendingPoolAddressesProvider = await ethers.getContractAt("ILendingPoolAddressesProvider", "0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5", account)
const lendingPoolAddress = await lendingPoolAddressesProvider.getLendingPool()
const lendingPool = await ethers.getContractAt("ILendingPool", lendingPoolAddress, account)
return lendingPool
}
async function approveErc20(erc20Address, spenderAddress, amountToSpend, account) {
const erc20Token = await ethers.getContract("IERC20", erc20Address, account)
const tx = await erc20Token.appove(spenderAddress, amountToSpend)
await tx.wait(1)
console.log("Approved!")
}
// Protocol takes everything as ERC-20
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error)
process.exit(1)
}) This is the error I get |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Jul 21, 2022
Replies: 1 comment 1 reply
-
- const erc20Token = await ethers.getContract("IERC20", erc20Address, account)
+ const erc20Token = await ethers.getContractAt("IERC20", erc20Address, account) getContract method updated to getContractAt |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
alymurtazamemon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@DaurenNope
getContract method updated to getContractAt