This boilerplate solves the HH502 error (unable to download compiler from the internet) by using a local Solidity compiler from node_modules.
- ✅ Works offline - uses local
solcfromnode_modules - ✅ Solves HH502 error - no need to download compiler from the network
- ✅ Hardhat 2.x configured - latest version with TypeScript support
- Node.js 18.x or 20.x (LTS versions)
- npm or yarn
⚠️ Important: Hardhat does not support Node.js versions above 20. If you have Node.js 23+, usenvmto switch:nvm install 20 nvm use 20
# Clone the repository
git clone <your-repo-url>
cd hello-hardhat
# Install dependencies
npm installThe problem is solved by overriding the TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD task in hardhat.config.ts:
subtask(
TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD,
async (args: { solcVersion: string }, hre, runSuper) => {
if (args.solcVersion === "0.8.28") {
const compilerPath = path.join(
__dirname,
"node_modules/solc/soljson.js"
);
return {
compilerPath,
isSolcJs: true,
version: args.solcVersion,
longVersion: "0.8.28+commit.xxx",
};
}
return runSuper();
}
);This forces Hardhat to use the local soljson.js instead of trying to download it from the internet.
npm run compile
# or
npx hardhat compilenpm run test
# or
npx hardhat testnpm run node
# or
npx hardhat nodenpx hardhat ignition deploy ./ignition/modules/Lock.ts- Copy
hardhat.config.tsto your project - Make sure
solcis installed:npm install --save-dev solc@0.8.28 - Update the Solidity version in the configuration if you're using a different version
- For other Solidity versions, add additional conditions in the
subtask
subtask(
TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD,
async (args: { solcVersion: string }, hre, runSuper) => {
const version = args.solcVersion;
if (version === "0.8.28" || version === "0.8.27") {
const compilerPath = path.join(
__dirname,
`node_modules/solc-${version}/soljson.js`
);
return {
compilerPath,
isSolcJs: true,
version: version,
longVersion: `${version}+commit.xxx`,
};
}
return runSuper();
}
);✅ Solved in this boilerplate - uses local compiler
If you see a warning about unsupported Node.js version:
- Use Node.js 18.x or 20.x (LTS)
- Install via
nvm:nvm install 20 && nvm use 20
Make sure solc is installed:
npm install --save-dev solc@0.8.28ISC