lesson 13, error Error: VM Exception while processing transaction: reverted with reason string 'SafeERC20: low-level call failed' #1846
-
got error back while trying to run scripts/aaveBorrow.js Error: VM Exception while processing transaction: reverted with reason string 'SafeERC20: low-level call failed'
at <UnrecognizedContract>.<unknown> (0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9)
at <UnrecognizedContract>.<unknown> (0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9) scripts/aaveBorrow.js: const { ethers, getNamedAccounts } = require("hardhat")
const { getWeth, AMOUNT } = require("./getWeth")
async function main() {
await getWeth()
const { deployer } = await getNamedAccounts()
const lendingPool = await getLendingPool(deployer)
console.log(`lendingPool address is: ${lendingPool.address}`)
// deposit
const wethTokenAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
// approve
approveErc20(wethTokenAddress, lendingPool.address, AMOUNT, 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.getContractAt("IERC20", erc20Address, account)
const tx = await erc20Token.approve(spenderAddress, amountToSpend)
await tx.wait(1)
console.log("approved")
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
hardhat.config.js: require("@nomiclabs/hardhat-waffle")
require("hardhat-gas-reporter")
require("@nomiclabs/hardhat-etherscan")
require("dotenv").config()
require("solidity-coverage")
require("hardhat-deploy")
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL || process.env.ALCHEMY_MAINNET_RPC_URL || ""
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || ""
const KOVAN_RPC_URL =
process.env.KOVAN_RPC_URL || "https://eth-mainnet.alchemyapi.io/v2/your-api-key"
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 ||
"https://eth-mainnet.g.alchemy.com/v2/yej0nNvaIUD7Lgo6uIjE7M3BMR2smg7N",
},
},
localhost: {
chainId: 31337,
},
kovan: {
url: KOVAN_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 42,
blockConfirmations: 6,
},
},
solidity: {
compilers: [
{
version: "0.8.8",
},
{
version: "0.6.12",
},
{
version: "0.4.19",
},
{ version: "0.6.6" },
],
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
gasReporter: {
enabled: true,
currency: "USD",
outputFile: "gas-report.txt",
noColors: true,
// coinmarketcap: COINMARKETCAP_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
},
},
} hope someone can help me with this error, thank you |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Aug 16, 2022
Replies: 2 comments 4 replies
-
@leung100 Please push the code to GitHub and leave link here I will check the issue. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
alymurtazamemon
-
thank you very very much !! |
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
@leung100 Please push the code to GitHub and leave link here I will check the issue.