Why don’t Hardhat named accounts resolve correctly in production when using environment variable overrides?
0 reputation · 05 May 2022, 08:31 UTC
When deploying a contract locally with Hardhat, named accounts (e.g., deployer) resolve to the expected address and the deployment succeeds. In the production environment, which connects to the Goerli testnet via an Infura endpoint, the same deployment script fails with an “address not found” error, even though the namedAccounts section in hardhat.config.js is identical.
Both environments use the same dotenv file to supply the private key for the deployer. Locally the key is loaded correctly, but in production the key appears to be ignored or overwritten, causing the named account lookup to return undefined.
What configuration or environment differences cause Hardhat to ignore the named account definition in production, and how can we ensure the named account is consistently resolved across both local and production deployments?