代码方式验证合约
出现如下报错
yarn hardhat run scripts/deploy.js --network speolia
yarn run v1.22.22
$ /Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/node_modules/.bin/hardhat run scripts/deploy.js --network speolia
deploy contract...
deploy contract to: 合约地址 这里隐藏
waitting for block taxes...
verifying contract...
UnexpectedError: An unexpected error occurred during the verification process.
Please report this issue to the Hardhat team.
Error Details: Connect Timeout Error
at Etherscan.isVerified (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/node_modules/@nomicfoundation/hardhat-verify/src/internal/etherscan.ts:126:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at SimpleTaskDefinition.action (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/node_modules/@nomicfoundation/hardhat-verify/src/internal/tasks/etherscan.ts:101:24)
at Environment._runTaskDefinition (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)
at Environment.run (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:192:14)
at SimpleTaskDefinition.action (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/node_modules/@nomicfoundation/hardhat-verify/src/index.ts:284:9)
at Environment._runTaskDefinition (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)
at Environment.run (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/node_modules/hardhat/src/internal/core/runtime-environment.ts:192:14)
at verify (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/scripts/deploy.js:31:9)
at main (/Users/macbook/Desktop/wjh/hhfcc/hardhatfcc/scripts/deploy.js:16:9)
current value: 5
update value: 7
✨ Done in 97.07s.
解决方法:
在hardhat.config.js中添加以下代码:
const { ProxyAgent, setGlobalDispatcher } = require("undici");
const proxyAgent = new ProxyAgent("http://127.0.0.1:1087");//查看自己的代理 修改端口
setGlobalDispatcher(proxyAgent);
yarn add --dev undici