{"content":{"title":"使用hardhat验证合约时，网络超时","body":"在hardhat中加入hardhat.config.js中加入如下代码即可。\r\n出处https://github.com/lxdao-official/gclx-contracts/issues/2\r\n\r\n```\r\nconst {setGlobalDispatcher,ProxyAgent} = require(\"undici\")\r\nconst proxyAgent = new ProxyAgent('http://127.0.0.1:4780')\r\nsetGlobalDispatcher(proxyAgent)\r\n```\r\n\r\n\r\n\r\n例子：\r\n\r\n```require(\"@nomicfoundation/hardhat-toolbox\");\r\nrequire(\"dotenv\").config();\r\n\r\n//给验证合约设置代理\r\nconst {setGlobalDispatcher,ProxyAgent} = require(\"undici\")\r\nconst proxyAgent = new ProxyAgent('http://127.0.0.1:4780')\r\nsetGlobalDispatcher(proxyAgent)\r\n\r\n/** @type import('hardhat/config').HardhatUserConfig */\r\n\r\nmodule.exports = {\r\n  defaultNetwork: \"goerli\",\r\n  etherscan: {\r\n    apiKey: process.env.ETHERSCAN_API_KEY, // 在 etherscan 中设置 API 密钥\r\n    // 增加超时时间（以毫秒为单位）\r\n    timeout: 600000, // 设置为 10 分钟的超时\r\n  },\r\n  networks: {\r\n    // 4. Add the Moonbase Alpha network specification\r\n    goerli: {\r\n      url: 'https://rpc.ankr.com/eth_goerli',\r\n      chainId: 5,\r\n      accounts: [process.env.BASE_GOERLI_PRIVATE_KEY]\r\n    },\r\n  },\r\n\r\n  solidity: {\r\n    version: \"0.8.9\",\r\n    settings: {\r\n      optimizer: {\r\n        enabled: true,\r\n        runs: 200\r\n      }\r\n    }\r\n  },\r\n\r\n};\r\n\r\n\r\n\r\n```"},"author":{"user":"https://learnblockchain.cn/people/1938","address":null},"history":null,"timestamp":1693591198,"version":1}