I have an ALCHEMY_MAINNET_RPC_URL environment that is of type string. I can verify it as such with:
const ALCHEMY_MAINNET_RPC_URL = process.env.ALCHEMY_MAINNET_RPC_URL || ''
console.log(typeof (ALCHEMY_MAINNET_RPC_URL))
And I get the output string.
In my config, I have a network setup as such:
const config: HardhatUserConfig = {
defaultNetwork: 'hardhat',
networks: {
mainnet_fork: {
chainId: 1,
forking: {
url: ALCHEMY_MAINNET_RPC_URL,
}
},
When trying to add this to my hardhat.config.ts, I keep getting the following error:
Error HH8: There's one or more errors in your config file:
- Invalid value undefined for HardhatConfig.networks.mainnet_fork.url - Expected a value of type string.
To learn more about Hardhat's configuration, please go to https://hardhat.org/config/
I've tried some different approaches like:
const ALCHEMY_MAINNET_RPC_URL = process.env.ALCHEMY_MAINNET_RPC_URL
const ALCHEMY_MAINNET_RPC_URL = process.env.ALCHEMY_MAINNET_RPC_URL!
but then I get:
Type 'undefined' is not assignable to type 'string'.
Or the same error.
Any thoughts?
.envfile in a sub dir by mistake, move it to project root dir, then it works. – Eric May 25 '22 at 17:15