-
Notifications
You must be signed in to change notification settings - Fork 3.2k
-
Solution Here 点击跳转至解决方案 - Solution Updated on 2023年11月22日
1. Problem Description
When I ran the verify
command line:
npx hardhat verify 0x2A3a6551B251C199De4748F545799c999b291C71 --network rinkeby
I got this TimeOut
error:
Error in plugin @nomiclabs/hardhat-etherscan: Failed to send contract verification request.
Endpoint URL: https://api-rinkeby.etherscan.io/api
Reason: Connect Timeout Error
2. Possible Cause
I'm in China, so I guess that's because China Great Firewall (GFW) polluted my DNS.
To test if so, I tried to ping the domain name of etherscan abi
according to this github answer
ping abi-rinkeby.etherscan.io
and got 100% package loss.
But after directly ping its IP address:
ping 104.22.15.57
I got 0% package loss.
Seems like it's caused by DNS pollution
.
3. New Problem After Solving the Cause
To solve the problem of DNS pollution
, I tried to manually map the connection between the domin and ip in the host
file:
104.22.14.57 api-rinkeby.etherscan.io
then run the verify
command line again. This time I get a new ECONNRESET
error the same to this github answer:
Error in plugin @nomiclabs/hardhat-etherscan: Failed to send contract verification request.
Endpoint URL: https://api-rinkeby.etherscan.io/api
Reason: read ECONNRESET
But I haven't found any answer about this error.
P.S. The connection problem occured after I ran this cammand npx hardhat clean
according to this github answer
4. Additional Information
My contract address in rinkeby is: 0x2A3a6551B251C199De4748F545799c999b291C71
.
The verify
section of deploy.js
file is:
const { run } = require("hardhat") async function verify(contractAddress, args) { try { await run("verify:verify", { address: contractAddress, constructorArgument: args, }) } catch (e) { console.log(e) } } verify("0x2A3a6551B251C199De4748F545799c999b291C71", [])
The error of running this code is the same to the verify
command line at the start.
The proxy I use is PandaVPN, and is in the mode of global mode
which means all data should go through the proxy and should be able to bypass the GFW.
I've been stuck on the problem for several days, and hope you can help me with some ideas.
P.S. Maybe you can verify the contract for me and see if it works.
Any reply to this problem is greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Hi,
I ran into similar issue, blocked me for a few days and following is my workaround.
Error messages I've met
# 1 NomicLabsHardhatPluginError: Failed to send contract verification request. Endpoint URL: https://api-rinkeby.etherscan.io/api Reason: Connect Timeout Error # 2 NomicLabsHardhatPluginError: Failed to send contract verification request. Endpoint URL: https://api-rinkeby.etherscan.io/api Reason: Client network socket disconnected before secure TLS connection was established
My workaround
Just like you, my first suspicion was on the GFW and I set up my hosts
file like you did.
ping
success with and without VPN, which means there is NO connection issue between our computers and ...
Replies: 15 comments 84 replies
-
@eiyen : First Copy paste this verify script in your verify.js
folder.
const { run } = require("hardhat")
const verify = async (contractAddress, args) => {
console.log("Verifying contract...")
try {
await run("verify:verify", {
address: contractAddress,
constructorArguments: args,
})
} catch (e) {
if (e.message.toLowerCase().includes("already verified")) {
console.log("Already verified!")
} else {
console.log(e)
}
}
}
module.exports = {
verify,
}
Beta Was this translation helpful? Give feedback.
All reactions
-
@eiyen : Then run this command : npx hardhat verify --network rinkeby DEPLOYED_CONTRACT_ADDRESS
Then let me know if it works!
Beta Was this translation helpful? Give feedback.
All reactions
-
I tried to run the verify.js
file with the code you gave me, but got an error of Connect Time Out
like this:
corror@CorrorCollins:~/web3-dev/hardhat-simple-storage-test$ npx hardhat verify --network rinkeby 0x2A3a6551B251C199De4748F545799c999b291C71
An unexpected error occurred:
ConnectTimeoutError: Connect Timeout Error
at onConnectTimeout (/home/corror/web3-dev/hardhat-simple-storage-test/node_modules/undici/lib/core/connect.js:131:24)
at /home/corror/web3-dev/hardhat-simple-storage-test/node_modules/undici/lib/core/connect.js:78:46
at Immediate._onImmediate (/home/corror/web3-dev/hardhat-simple-storage-test/node_modules/undici/lib/core/connect.js:119:9)
at processImmediate (node:internal/timers:466:21) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
Beta Was this translation helpful? Give feedback.
All reactions
-
@eiyen : Send your repo link, Will into that
Beta Was this translation helpful? Give feedback.
All reactions
-
@eiyen : Send your repo link, Will into that
Maybe that's because of the connection problem. Just when I was trying to push a project to github through the command git push -u origin master
, there was no response of this command.
I think maybe the further reason is that my windows can use the proxy but WSL-2 cannot.
Beta Was this translation helpful? Give feedback.
All reactions
-
Can someone help me
https://github.com/smartcontractkit/full-blockchain-solidity-course-js/discussions/3504
Beta Was this translation helpful? Give feedback.
All reactions
-
Hey @eiyen please share your contract code, I need to compile it, get the abi, and see if I am able to verify it myself.
Beta Was this translation helpful? Give feedback.
All reactions
-
This is my contract code of SimpleStorage.sol
:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; contract SimpleStorage { uint256 favoriteNumber; mapping(string => uint256) public nametoFavoriteNumber; // struct refers to customed object type struct People { string name; uint256 favoritNumber; } // Syntax of variable initiation: [object type] [visibility] [variable name] People[] public people; function store(uint256 _favoriteNumber) public { favoriteNumber = _favoriteNumber; } function retrieve() public view returns (uint256) { return favoriteNumber; } function addPerson(string memory _name, uint256 _favoriteNumber) public { // The `People` object is: People{} // The `People` instance is: People() people.push(People(_name, _favoriteNumber)); nametoFavoriteNumber[_name] = _favoriteNumber; } }
Beta Was this translation helpful? Give feedback.
All reactions
-
Can someone help me, thanks
#3504
Beta Was this translation helpful? Give feedback.
All reactions
-
@eiyen : your deploy script please!
Beta Was this translation helpful? Give feedback.
All reactions
-
This is my deploy.js
file:
/* Module Requirement */ require("dotenv").config /**Hardhat Package Usage: * 1. ethers: create Factory, deploy contract, wait for confirmation. * 2. run: verify contract. * 3. network: check configuration */ const { ethers, run, network } = require("hardhat") /* Main Function */ async function main() { /* 1. Deploy Section */ const SimpleStorageFactory = await ethers.getContractFactory( "SimpleStorage" ) console.log("Deploying...") const simpleStorage = await SimpleStorageFactory.deploy() console.log(`Get Address: ${simpleStorage.address}`) console.log("Pending...") await simpleStorage.deployed() console.log("Deployed!") /* 2. Verify Section */ if ( process.env.ETHERSCAN_API_KEY && (network.config.chainId === 4 || network.config.chainId === 420) ) { /**Why we need to wait for a few more block confirmation? * 1. EtherScan need a few seconds to find the contract just deployed. * 2. We use EtherScan API for verification. * So we need to wait EtherScan to find the contract first before we can use it. */ console.log("Waiting for 6 block confirmation...") await simpleStorage.deployTransaction.wait(6) console.log("Comfirmed!") console.log("Verifying...") await verify(simpleStorage.address, []) console.log("Verified!") } } /* Verify Function */ async function verify(contractAddress, args) { try { /**About "verify:verify": * The first verify is a name in the type of string * The second verify is the task of verify */ await run("verify:verify", { address: contractAddress, constructorArgument: args, }) } catch (e) { /**Why we need a try... catch.. here? * To throw the error if the verification get wrong. */ if (e.message.toLowerCase().includes("already verified")) { console.log("Already Verified!") } else { console.log(e) } } } /* Executor Function */ main() .then(() => process.exit(0)) .catch((error) => { console.log(error) process.exit(1) })
Beta Was this translation helpful? Give feedback.
All reactions
-
Can someone help me, thanks
#3504
Beta Was this translation helpful? Give feedback.
All reactions
-
@eiyen I have noticed you are not using the correct command. Please try npx hardhat deploy --network rinkeby
and show me your console if you face error.
Beta Was this translation helpful? Give feedback.
All reactions
-
@alymurtazamemon I got unrecognized task
after I ran this command. The errer report is:
When I ran yarn hardhat help
, I found there is no task named deploy
.
The way to deploy a contract according to the hardhat deploy documentation is to write a deploy script and then run it.
Beta Was this translation helpful? Give feedback.
All reactions
-
@eiyen Make sure you require("hardhat-deploy");
in the hardhat file
Beta Was this translation helpful? Give feedback.
All reactions
-
@eiyen And these two packages in the package.json
file "hardhat-deploy": "^0.11.11",
& "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @alymurtazamemon, according to your reply, I tried these steps:
- ran the command:
yarn hardhat --dev add hardhat-deploy
- checked my
package.json
file and foundhardhat-deploy
and@nomiclabs/hardhat-ethers
devDependencies. - added the code
require("hardhat-deploy")
intodeploy.js
file - ran the command:
npx hardhat deploy --network rinkeby
But I also got the error same to my last reply called Error HH303: Unrecognized task deploy
.
Beta Was this translation helpful? Give feedback.
All reactions
-
Can someone help me, thanks
#3504
Beta Was this translation helpful? Give feedback.
All reactions
-
I also meet this problem and find a way to solve it perfectly.
add the code into hardhat.config.js
const { ProxyAgent, setGlobalDispatcher } = require("undici")
const proxyAgent = new ProxyAgent("http://127.0.0.1:7890") // change to yours
setGlobalDispatcher(proxyAgent)
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @Wmengti
It seems like the right direction to solve the ECONNRESET problem. But after I tried this, I get a new error called ECONNREFUSED. The following is the details of this problem.
What I tried
According to my VPN configuration:
I added the code into the hardhat.config.js
file and changed the code into mine with port 7890
like this:
const proxyUrl = "http://127.0.0.1:7890" // change to yours, With the global proxy enabled, change the proxyUrl to your own proxy link. The port may be different for each client. const { ProxyAgent, setGlobalDispatcher } = require("undici") const proxyAgent = new ProxyAgent(proxyUrl) setGlobalDispatcher(proxyAgent)
Error I got
However, after ran my deploy.js file, I got a new error called ECONNREFUSED
, which indicates that the user is trying to connect to your server and is unable to connect to the port. The full error is
Verifying...
Nothing to compile
NomicLabsHardhatPluginError: Failed to obtain list of solc versions. Reason: connect ECONNREFUSED 127.0.0.1:7890
at getVersions (/home/corror/web3-dev/hardhat-simple-storage-test/node_modules/@nomiclabs/hardhat-etherscan/src/solc/version.ts:46:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at getLongVersion (/home/corror/web3-dev/hardhat-simple-storage-test/node_modules/@nomiclabs/hardhat-etherscan/src/solc/version.ts:17:20)
at SimpleTaskDefinition.verifySubtask [as action] (/home/corror/web3-dev/hardhat-simple-storage-test/node_modules/@nomiclabs/hardhat-etherscan/src/index.ts:293:7)
at Environment._runTaskDefinition (/home/corror/web3-dev/hardhat-simple-storage-test/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
at Environment.run (/home/corror/web3-dev/hardhat-simple-storage-test/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
at verify (/home/corror/web3-dev/hardhat-simple-storage-test/scripts/deploy.js:56:9)
at main (/home/corror/web3-dev/hardhat-simple-storage-test/scripts/deploy.js:36:9)
Caused by: Error: connect ECONNREFUSED 127.0.0.1:7890
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
Can I take a look at your VPN settings and your VPN name? Maybe I can buy one as yours and then try your method again.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Can someone help me, thanks
#3504
Beta Was this translation helpful? Give feedback.
All reactions
-
const proxyUrl = "http://127.0.0.1:7890" // change to yours, With the global proxy enabled, change the proxyUrl to your own proxy link. The port may be different for each client. const { ProxyAgent, setGlobalDispatcher } = require("undici") const proxyAgent = new ProxyAgent(proxyUrl) setGlobalDispatcher(proxyAgent)
it's worked!
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi,
I ran into similar issue, blocked me for a few days and following is my workaround.
Error messages I've met
# 1 NomicLabsHardhatPluginError: Failed to send contract verification request. Endpoint URL: https://api-rinkeby.etherscan.io/api Reason: Connect Timeout Error # 2 NomicLabsHardhatPluginError: Failed to send contract verification request. Endpoint URL: https://api-rinkeby.etherscan.io/api Reason: Client network socket disconnected before secure TLS connection was established
My workaround
Just like you, my first suspicion was on the GFW and I set up my hosts
file like you did.
ping
success with and without VPN, which means there is NO connection issue between our computers and the domain.
Since there was almost no waiting time when my console emit the error messages,
it really didn't feel like a timeout error.
secure TLS connection
in the error message got my attention.
Is there a way we could modify the endpoint URL to http
protocol?
Luckily yes:
https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan#adding-support-for-other-networks
I tried the following:
etherscan: { apiKey: { rinkeby: "<rinkeby-api-key>" }, customChains: [ { network: "rinkeby", chainId: 4, urls: { apiURL: "http://api-rinkeby.etherscan.io/api", // https => http browserURL: "https://rinkeby.etherscan.io" } } ] }
Then everything works with and without VPN.
Downside of the workaround
If, one day, etherscan.io
demise its http
protocol support. We will ran into the same issue again......
Finally
I can see there may be other issues you came across, please try deploy, store and retrieve first, make sure other things works well, then open up your verify function and try above configs.
Hope this helps :)
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 7
-
都是中国人的问题,都用英语探讨解决,好讽刺
哈哈哈
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
没戏,试了customChains,用http也一样没戏
Beta Was this translation helpful? Give feedback.
All reactions
-
找到了稳定的解决方法,详见下面的回答。
Beta Was this translation helpful? Give feedback.
All reactions
-
I have same problem in Iran since we are using china GFW, And this did not work for me got this error for mumbai
The HTTP server response is not ok. Status code: 301 Response text:
Beta Was this translation helpful? Give feedback.
All reactions
-
我加了 之前可以用 现在报这个错误了 InvalidArgumentError: Proxy opts.uri is mandatory
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks,I also solved the problem in your way.It may be necessary to open the proxy during configuration, you can use the global mode of clash and open TUN in the consolel.I solved it this way.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 3
-
thanks,bro,it works
Beta Was this translation helpful? Give feedback.
All reactions
-
I tried setting up a terminal proxy and an npm proxy, but both failed.
The core problem is DNS pollution, I modify the host file and get succeed.
Beta Was this translation helpful? Give feedback.
All reactions
-
问题是那个url的ip也是需要翻墙的,最后还得在hardhat配置中修改代理
Beta Was this translation helpful? Give feedback.
All reactions
-
你们的讨论是有意义的,感谢。
Beta Was this translation helpful? Give feedback.
All reactions
-
找到了该网络问题解决方法:
-
局域网翻墙
以翻墙软件 Clash Verge 为例(Clash for Windows 已删库),局域网翻墙的配置如下:
image -
终端翻墙:
TUN 模式下终端也能够默认翻墙,操作方法为:先通过服务模式下载必要内容,再打开 TUN 模式。详见下图:
image -
在
hardhat.config.js
中添加以下代码:const { ProxyAgent, setGlobalDispatcher } = require("undici"); const proxyAgent = new ProxyAgent("http://127.0.0.1:7890"); setGlobalDispatcher(proxyAgent);
以上代码用来告诉程序按照本地代理链接网络。
记得安装
undici
依赖包:npm install --save-dev undici
按照以上方法,可以顺利部署并测试合约。
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 35
-
帅啊
Beta Was this translation helpful? Give feedback.
All reactions
-
为什么我运行了 npm install --save-dev undici
之后再运行 yarn hardhat run .\scripts\deploy.js --network sepolia
就爆错
error Command "hardhat" not found.
Beta Was this translation helpful? Give feedback.
All reactions
-
run yarn install
Beta Was this translation helpful? Give feedback.
All reactions
-
WSL2
我mac 用的v2ray 翻墙, 如何解决上述问题
Beta Was this translation helpful? Give feedback.
All reactions
-
按照这样设置了还是没用是为什么额,报这个错
A network request failed. This is an error from the block explorer, not Hardhat. Error: read ECONNRESET
Beta Was this translation helpful? Give feedback.
All reactions
-
补一个在mac上的用clash开启LAN的截图
clashx下载: https://repo.trojan-cdn.com/clashX/LatestRelease/ClashX.dmg
iShot_2023年06月01日_16 40 26Beta Was this translation helpful? Give feedback.
All reactions
-
👍 4
-
上面都是windows和mc的,这里分享一个win11下的wsl子系统吧,我用的是ubuntu20.4
主要是wsl如何跨过win防火墙使用代理的问题
step1:请记住第五步的名字(vEthernet (WSL (Hyper-V firewall))),请用英文括号,记得不要忘记空格
d58166165895003542ac84aa821f5d9step2:
主机之间是有防火墙的, 现在我们要关闭它
以管理员的身份打开powershell,输入以下命令,记得把上面记录下来的名字替换到 -InterfaceAlias后面,出现图中的提示就是成功
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allow
step3:
clash的配置和上面这位大佬一样
step4:子系统配置
## 获取主机 IP ## 主机 IP 保存在 /etc/resolv.conf 中 wsl2需要通过这个ip访问windows export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
然后粘贴下面的脚本并运行
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*') alias setss='export https_proxy="http://${hostip}:7890";export http_proxy="http://${hostip}:7890";export all_proxy="socks5://${hostip}:7890";' alias unsetss='unset all_proxy'
上面的脚本只影响当前会话 不必担心会把wsl的网络搞崩 重新启动个shell这些环境都没了
如果觉得每次粘贴麻烦 可以将这脚本粘贴到用户目录下的.zshrc配置文件或bash的配置文件中
或保存为任意文件每次运行source <保存的脚本文件名>
测试一下
6c32d9f8546f873016b16863e630756
step5:验证智能合约 ps:***不需要在hardhat.config.js里面配置代理了,这里已经用主机代理,注释掉代码就可以
90f1b245d0ab0d8b7c6e83b9e66bdc8 aabbedbc95c218a0783770b525e9777 bingo!Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
解决问题了,感谢
Beta Was this translation helpful? Give feedback.
All reactions
-
微信图片_20240807024304
大家好,我在用 hardhat 18.20.4 版本,yarn 1.22.22 验证合约时,报了这个错误
NetworkRequestError: A network request failed. This is an error from the block explorer, not Hardhat. Error: Response does not match the HTTP/1.1 protocol (Expected HTTP/)
这个错误要怎么解决呢?
Beta Was this translation helpful? Give feedback.
All reactions
-
I had this issue on Windows 10, but after upgrading to Windows 11, here's what worked for me (if you're also on Windows 11):
- Open PowerShell as admin and run:
wsl --update --pre-release
-
Edit your
.wslconfig
file:- Navigate to
%UserProfile%
in File Explorer (typicallyC:\Users\<UserName>\.wslconfig
) - Add these settings:
- Navigate to
[wsl2] nestedVirtualization=true ipv6=true [experimental] autoMemoryReclaim=gradual # gradual | dropcache | disabled networkingMode=mirrored dnsTunneling=true firewall=true autoProxy=true
- Reboot WSL:
wsl --shutdown wsl -l -v wsl -t <Name> wsl -l -v wsl exit wsl -l -v
- Try running
yarn hardhat run...
again
Beta Was this translation helpful? Give feedback.