# How to use HardHat behind a proxy

I'm using HardHat (repo) behind a firewall, requiring outbound connections to use a proxy. This is usually pretty easy, for example to configure NPM for using proxy, you can set environment variables HTTP_PROXY and HTTPS_PROXY.

In HardHat, when running commands like npx hardhat compile, HardHat reaches out to https://solc-bin.ethereum.org/windows-amd64/list.json to get the latest version list of the solidity compiler solc. The command fails because it cannot reach out to that address, making the fetch fail and subsequently the command fail. (Error message is below with Stack Trace)

Is there...

A) Configure HardHat to work with a proxy?

or

B) Manually install solc (with something like yarn add solc and update hardhat.config.js) and disable HardHat from checking for a list of compilers and installing a compiler?

Error:

HardhatError: HH502: Couldn't download compiler versions list. Please check your connection.

Caused by: FetchError: request to https://solc-bin.ethereum.org/windows-amd64/list.json failed, reason: read ECONNRESET
at ClientRequest.<anonymous> (C:\Projects\myProject\node_modules\node-fetch\lib\index.js:1461:11)
at ClientRequest.emit (events.js:315:20)
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)


Edit/Update:

I found the task name subtask(TASK_COMPILE_SOLIDITY_RUN_SOLCJS) to compile using solcjs. Is there a way to configure solcjs as the default compiler? Possibly through an ENV variable?

Update May 2021:

They are trying to resolve this issue.

https://github.com/nomiclabs/hardhat/pull/1291

• Yes. I’ve been waiting on the PR to be merged for a little while. If you’re waiting on this too, please add a comment or “up vote” the issue github.com/nomiclabs/hardhat/issues/1280 related to the PR May 2, 2021 at 14:46
• Done. Hope this feature can be added soon. May 4, 2021 at 5:40
• Agreed. I’ve been waiting since March and cannot wait any longer. I’ll have to use truffle and web3 possibly. Is there a way to use ethers with mocha with truffle? May 4, 2021 at 12:17
• You can use ethers.js as an independent package in your truffle project. ethereum.stackexchange.com/questions/50632/… May 5, 2021 at 4:39
• Compare with Java, Blockchain=server+db, evm=jvm, solidity=java, hardhat/truffle=eclipse, oppenzepellin=spring framework, ethers/web3=RESTful API, ABI=API controller. May 5, 2021 at 4:50

I faced similar issue. However, for me hardhat is not able to download list of compiler versions behind corporate proxy. Tried a lot of things. No luck. After a lot of trial and errors, found a way to make this work. Download list.json and keep it locally at C:\Users\<your-user>\AppData\Local\hardhat-nodejs\Cache\compilers\windows-amd64 (windows). Also, download the solidity compiler executable for windows (required version) from https://github.com/ethereum/solidity/releases and place it in the same folder mentioned above. Now, peruse your list.json and identify the object for the solc compiler version of interest. Rename the executable as with the long name given in path in that object. For e.g., if you need solc version 0.8.0, the path in list.json for 0.8.0 version is solc-windows-amd64-v0.8.4+commit.c7e474f2.exe. Use this to rename the downloaded executable. Now, run npm test. This should fix the issue.

There is also an interesting way to run the compiler within docker on windows. For this, follow the discussion here - https://github.com/NomicFoundation/hardhat/issues/1280

HardHat has added the functionality to set in proxies HTTP_PROXY and HTTPS_PROXY the config as @beijingjazzpanda noted with PR1291.

WARNING

Hardhat will automatically download the versions of solc that you set up. If you are behind an HTTP proxy, you may need to set the HTTP_PROXY or HTTPS_PROXY environment variable to the URL of your proxy.

For some situations where internet access may not be available, consider extending the hardhat.config.js as shown in this example to reference a specific solc version, similar to the following:

const { TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD } = require("hardhat/builtin-tasks/task-names");
const path = require("path");

if (args.solcVersion === "0.8.5") {
const compilerPath = path.join(__dirname, "soljson-v0.8.5-nightly.2021.5.12+commit.98e2b4e5.js");

return {
compilerPath,
isSolcJs: true, // if you are using a native compiler, set this to false
version: args.solcVersion,
// this is used as extra information in the build-info files, but other than
// that is not important
longVersion: "0.8.5-nightly.2021.5.12+commit.98e2b4e5"
}
}

// we just use the default subtask if the version is not 0.8.5
return runSuper();
})

module.exports = {
solidity: "0.8.5",
};