Lessson 13 : Not getting LendingPool Address in the output, instead getting "Got 200000.... WETH " twice #5771
Answered
by
alfaqi
Prayag2003
asked this question in
Q&A
-
![]() Getting the "Got 200000.... WETH " twice in the output terminal. But instead , i was looking for " Got 20000... WETH" and next line to be the contract address of Lending Pool , which is not getting printed Youtube TimeStamp : https://youtu.be/gyMwXuJrbJQ?t=71490 Below are
const { getWeth } = require("../scripts/getWeth");
const { getNamedAccounts } = require("hardhat");
async function getLendingPool(account) {
const ILendingPoolAddressesProvider = await ethers.getContractAt(
"ILendingPoolAddressesProvider",
"0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5", // Lending Pool address
account
);
const lendingPoolAddress = await ILendingPoolAddressesProvider.getLendingPool();
const lendingPool = await ethers.getContractAt("ILendingPool", lendingPoolAddress, account);
return lendingPool;
}
async function main() {
await getWeth();
const { deployer } = getNamedAccounts();
// Interacting with the AAVE Protocol -> to interact we need ABI and Address
// Lending Pool address : 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5
const lendingPool = await getLendingPool(deployer);
console.log(`Lending Pool Address : ${lendingPool.address} .`)
}
main()
.then(() => process.exit(0))
.catch((err) => {
console.log(err);
process.exit(1);
})
const { getNamedAccounts } = require("hardhat");
const { ethers } = require("hardhat");
const AMOUNT = ethers.utils.parseEther("0.01");
async function getWeth() {
const { deployer } = await getNamedAccounts();
// call the deposit function on the WETH Contract
// abi , contract address
// 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
const iWeth = await ethers.getContractAt(
"IWeth", // ABI
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // Contract Address
deployer
);
const tx = await iWeth.deposit({ value: AMOUNT });
await tx.wait(1);
const wethBalance = await iWeth.balanceOf(deployer);
console.log(`Got ${wethBalance.toString()} WETH Balance`);
}
getWeth()
.then(() => process.exit(0))
.catch((err) => {
console.log(err);
process.exit(1);
})
module.exports = { getWeth, AMOUNT }; ``` hardhat.config.js ``` require("hardhat-gas-reporter")
require("dotenv").config()
require("@nomiclabs/hardhat-waffle")
require("solidity-coverage")
require("hardhat-deploy")
const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL
const COINMARKET_API_KEY = process.env.COINMARKET_API_KEY
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 31337,
forking: {
url: MAINNET_RPC_URL,
},
},
localhost: {
chainId: 31337,
},
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 5,
blockConfirmations: 6,
},
},
solidity: {
compilers: [
{
version: "0.8.8",
},
{
version: "0.6.12",
},
{
version: "0.4.19",
},
],
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
gasReporter: {
enabled: true,
currency: "USD",
outputFile: "gas-report.txt",
noColors: true,
coinmarketcap: COINMARKET_API_KEY,
},
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another
},
},
} ``` package.json ``` {
"name": "erc20-tokens",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@aave/protocol-v2": "^1.0.1",
"@nomicfoundation/hardhat-ethers": "^3.0.3",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@openzeppelin/contracts": "^4.9.2",
"@types/sinon-chai": "^3.2.9",
"dotenv": "^16.3.1",
"ethereum-waffle": "^4.0.10",
"ethers": "^5.7.2",
"hardhat": "^2.16.1",
"hardhat-deploy": "^0.11.34",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-shorthand": "^1.0.0",
"solidity-coverage": "^0.8.3"
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
alfaqi
Jul 2, 2023
Replies: 2 comments
-
the issue with this additional code in getWeth()
.then(() => process.exit(0))
.catch((err) => {
console.log(err);
process.exit(1);
}) just delete it, and it works fine. const { getNamedAccounts } = require("hardhat");
const { ethers } = require("hardhat");
const AMOUNT = ethers.utils.parseEther("0.01");
async function getWeth() {
const { deployer } = await getNamedAccounts();
// call the deposit function on the WETH Contract
// abi , contract address
// 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
const iWeth = await ethers.getContractAt(
"IWeth", // ABI
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // Contract Address
deployer
);
const tx = await iWeth.deposit({ value: AMOUNT });
await tx.wait(1);
const wethBalance = await iWeth.balanceOf(deployer);
console.log(`Got ${wethBalance.toString()} WETH Balance`);
}
module.exports = { getWeth, AMOUNT }; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Prayag2003
-
Oh completely missed that 😅. It's working now. Thanks @alfaqi |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the issue with this additional code in
getWeth.js
just delete it, and it works fine.
like this
getWeth.js