1

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.
    at CompilerDownloader.downloadCompilersList (C:\Projects\myProject\node_modules\hardhat\src\internal\solidity\compiler\downloader.ts:185:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

    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)
        at processTicksAndRejections (internal/process/task_queues.js:84:21)

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:

3 Answers 3

1

They are trying to resolve this issue.

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

7
  • 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
    – DogEatDog
    May 2, 2021 at 14:46
  • 1
    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?
    – DogEatDog
    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
  • 1
    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
1

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

0

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");

subtask(TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD, async (args, hre, runSuper) => {
  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",
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.