network.config is not a function #4688
-
I know I should be able to troubleshoot this on my own, but I've been on it around 30 minutes already and can't find where the problem is ocurring. Error promptError: ERROR processing /home/philipo0/hh-fcc/hardhat-fund-me-fcc/deploy/01-deploy-fund-me.js: helper-hardhat-config.jsconst networkConfig = {
31337: {
name: "localhost"
},
// Price Feed Address, values can be obtained at https://docs.chain.link/docs/reference-contracts
5: {
name: "goerli",
ethUsdPriceFeed: "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e"
},
137: {
name: "polygon",
ethUsdPriceFeed: "0xF9680D99D6C9589e2a93a78A04A279e509205945"
}
}
const developmentChains = ["hardhat", "localhost"]
const DECIMALS = 8
const INITIAL_ANSWER = 200000000000
module.exports = {
networkConfig,
developmentChains,
DECIMALS,
INITIAL_ANSWER
} 01-deploy-fund-me.js//import
//main funciton
//calling main function
// function deployFunc(hre) {
// console.log("hi there!")
// }
// module.exports.default = deployFunc
// module.exports = async (hre) => {
// const { getNamedAccounts, deployments } = hre
const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { network } = require("hardhat")
const { verify } = require("../utils/verify")
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
//if chainId is X use address Y
//if chainId is Z use address W
//const ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
let ethUsdPriceFeedAddress
if (developmentChains.includes(network.name)) {
const ethUsdAggregator = await deployments.get("MockV3Aggregator")
ethUsdPriceFeedAddress = ethUsdAggregator.address
} else {
ethUsdPriceFeedAddress = network.config(network.name)["ethUsdPriceFeed"]
}
//if contracts doesn't exist, we deploy a minimal version of it for our local test
//what happens when we want to change chains
//when going for localhost or hardhat network we will deploy the mock contract
const args = [ethUsdPriceFeedAddress]
const fundMe = await deploy("FundMe", {
from: deployer,
args: args, //put price feed address here
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(fundMe.address, args)
}
log("----------------------------------")
}
module.exports.tags = ["all", "fundme"] hardhat.config.jsrequire("@nomiclabs/hardhat-waffle")
require("hardhat-gas-reporter")
require("@nomiclabs/hardhat-etherscan")
require("dotenv").config()
require("solidity-coverage")
require("hardhat-deploy")
/**
* @type import('hardhat/config').HardhatUserConfig
*/
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY
const GOERLI_RPC_URL = process.env.GOERLI_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
// gasPrice: 130000000000,
},
goerli: {
url: GOERLI_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 5,
blockConfirmations: 6,
}
},
solidity: {
compilers: [
{
version: "0.8.8"
},
{
version: "0.6.6"
}
]
},
etherscan: {
apiKey: ETHERSCAN_API_KEY
// customChains: [], // uncomment this line if you are getting a TypeError: customChains is not iterable
},
gasReporter: {
enabled: false,
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
}
},
mocha: {
timeout: 500000
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@philipo0 You are used |
Beta Was this translation helpful? Give feedback.
-
Hi @philipo0 , You used parentheses instead of brackets in this line : Pay extra attention to the error message. It tells you the line where the error is (in this case 31/34) and gives you information. Here, you're told "networkConfig is not a function" which means that you wrote networkConfig() somewhere. Cheers 😄 |
Beta Was this translation helpful? Give feedback.
Hi @philipo0 ,
You used parentheses instead of brackets in this line :
ethUsdPriceFeedAddress = network.config(network.name)["ethUsdPriceFeed"]
It should instead be
ethUsdPriceFeedAddress = network.config[network.name]["ethUsdPriceFeed"]
Pay extra attention to the error message. It tells you the line where the error is (in this case 31/34) and gives you information. Here, you're told "networkConfig is not a function" which means that you wrote networkConfig() somewhere.
Cheers 😄