Hardhat CLI and Solc Compiler: Default Version Selection
0 reputation · 07 Aug 2024, 15:46 UTC
0 reputation · 07 Aug 2024, 15:46 UTC
31775 reputation · 07 Aug 2024, 18:01 UTC
Hardhat uses the solc version bundled with the installed Hardhat release when hardhat.config.js lacks a solidity field. That version is fixed per Hardhat release (for example, Hardhat 2.22.x bundles solc 0.8.24) and can change between minor releases. There is no separate "default" that persists across upgrades; the compiler version follows the Hardhat package version.
Plugins such as @typechain/hardhat read the compiler version from the build-info artifacts (artifacts/build-info/*.json). If you upgrade Hardhat and the bundled solc changes, the next compile uses the new version, but previously generated typings may have been produced with the old one. This mismatch can cause silent type errors or missing types because the plugin assumes the compilation and type-generation steps share the same compiler.
solidity ConfigTwo practical approaches keep the compiler stable across Hardhat updates:
package.json (e.g., "hardhat": "2.22.0") and avoid automatic minor/patch upgrades. This is the most reliable method because the bundled solc is part of the Hardhat release.SOLC_VERSION environment variable to the exact version string shipped with your pinned Hardhat release (e.g., SOLC_VERSION=0.8.24). Hardhat respects this variable for the bundled compiler only; it does not download arbitrary versions.Both methods avoid adding a solidity block to the config while preventing surprise compiler changes.
Run one of the following to see the exact solc version invoked during a default compile:
npx hardhat compile --verbose 2>&1 | grep -i "solidity compiler version"
Or inspect the generated build-info files:
cat artifacts/build-info/*.json | jq -r '.compiler.version' | sort -u
Both commands reveal the compiler version Hardhat actually executed, independent of what the release notes claim.
Does your project already commit artifacts/build-info/ or rely on a CI cache that might serve stale build-info from a previous Hardhat version? If yes, clear the artifacts (npx hardhat clean) before verifying, otherwise the compiler.version field may reflect an older run.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.