问题背景
今天在学习使用Hardhat进行verify 合约 到 Ethscan的时候,出现了如下报错
fafa@fafadeMacBook-Air Web3_Solidity_Study % npx hardhat verify --network sepolia XXXXXXXXXXXXXXXXXXXXXXXX "10"
Successfully verified contract FundMe on Sourcify.
https://repo.sourcify.dev/contracts/full_match/11155111/XXXXXXXXXXXXXXXXXXXXXXXXX/
hardhat-verify found one or more errors during the verification process:
Etherscan:
A network request failed. This is an error from the block explorer, not Hardhat. Error: Connect Timeout Error
从这个报错信息中,可以看出是超时问题,一般超时问题是网络原因导致的。
解决方案
Windows
-
局域网
-
终端:
-
在
<font style="color:rgb(31, 35, 40);">hardhat.config.js</font>
中添加以下代码:
const { ProxyAgent, setGlobalDispatcher } = require("undici");
const proxyAgent = new ProxyAgent("http://127.0.0.1:7890");
setGlobalDispatcher(proxyAgent);
以上代码用来告诉程序按照本地代理链接网络。
记得安装 <font style="color:rgb(31, 35, 40);">undici</font>
依赖包:
npm install --save-dev undici
Mac
mac设置LAN的方式如下,按照我下面这张图即可