I am trying to read variable values from my .env
file here, but all I am getting is values are undefined.
require("@nomicfoundation/hardhat-toolbox")
require('dotenv').config()
const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
module.exports = {
defaultNetwork: 'hardhat',
networks: {
rinkeby: {
url: RINKEBY_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 4,
}
},
solidity: "0.8.8",
};
Error:
Error HH8: There's one or more errors in your config file:
* Invalid value undefined for HardhatConfig.networks.rinkeby.url - Expected a value of type string.
* Invalid account: #0 for network: rinkeby - Expected string, received undefined
To learn more about Hardhat's configuration, please go to https://hardhat.org/config/
I have filled my .env
file like this:
RINKEBY_RPC_URL=dummyUrl.com
PRIVATE_KEY=13133private90994
I have tested my code by directly putting RPC URL and private key in my config file and it is working successfully, conforming it is an env file issue.
BTW, I'm using a Macbook pro with the new M1 Pro, maybe OS is causing this issue?
any thoughts on why this issue is occurring?