首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在代理后面使用HardHat

如何在代理后面使用HardHat
EN

Ethereum用户
提问于 2021-02-26 20:08:08
回答 3查看 3.2K关注 0票数 1

我在防火墙后面使用HardHat (存储库),要求出站连接使用代理。这通常非常容易,例如,对于配置NPM来说,要使用代理,可以设置环境变量HTTP_PROXYHTTPS_PROXY

在HardHat中,当运行像npx hardhat compile这样的命令时,HardHat会向https://solc-bin.ethereum.org/windows-amd64/list.json伸出手来获取solidity编译器solc的最新版本列表。该命令失败,因为它无法到达该地址,导致获取失败,随后命令失败。(下面是带有堆栈跟踪的错误消息)

有没有..。

( A)配置HardHat以使用代理?

( B)手动安装solc (比如yarn add solc和update hardhat.config.js),禁止HardHat检查编译器列表和安装编译器?

错误:

代码语言:javascript
复制
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)

编辑/更新:

我找到了使用solcjs编译的任务名_编译_坚固性_跑_( SOLCJS)。是否有方法将solcjs配置为默认编译器?可能是通过ENV变量?

2021年5月更新:

EN

回答 3

Ethereum用户

回答已采纳

发布于 2021-08-22 14:59:14

HardHat添加了在代理、HTTP_PROXYHTTPS_PROXY 配置中设置的功能,就像@beijingjazz熊猫PR1291中指出的那样。

警告安全帽将自动下载您设置的solc版本。如果您在HTTP代理后面,则可能需要将HTTP_PROXY或HTTPS_PROXY环境变量设置为代理的URL。

对于可能无法访问internet的某些情况,请考虑扩展hardhat.config.js,如这个例子中所示,以引用特定的solc版本,类似于以下内容:

代码语言:javascript
复制
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",
};
票数 0
EN

Ethereum用户

发布于 2021-04-27 03:39:06

他们正在设法解决这个问题。

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

票数 1
EN

Ethereum用户

发布于 2022-04-11 08:30:38

我也面临着类似的问题。然而,对我来说,hardhat无法下载公司代理背后的编译器版本列表。尝试了很多事情。不走运。经过大量的尝试和错误,找到了一种方法来使这一工作。下载list.json并将其保存在C:\Users\<your-user>\AppData\Local\hardhat-nodejs\Cache\compilers\windows-amd64 (windows)的本地。另外,从https://github.com/ethereum/solidity/releases下载windows的solidity编译器可执行文件(必需版本),并将其放在上面提到的文件夹中。现在,仔细阅读list.json并为感兴趣的solc编译器版本标识对象。将可执行文件重命名为该对象中在path中给出的长名称。例如,如果您需要solc version 0.8.0,则list.json For 0.8.0版本中的pathsolc-windows-amd64-v0.8.4+commit.c7e474f2.exe。使用此方法重命名下载的可执行文件。现在,运行npm test。这应该能解决问题。

还有一种有趣的方法可以在windows上的docker中运行编译器。为此,请按照这里的讨论- https://github.com/NomicFoundation/hardhat/issues/1280

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/93981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档