使用hardhat验证合约时,网络超时

  • 志辉
  • 更新于 2023-09-02 01:59
  • 阅读 1129

在hardhat中加入hardhat.config.js中加入如下代码即可。出处https://github.com/lxdao-official/gclx-contracts/issues/2const{setGlobalDispatcher,ProxyAgent}=require("u

在hardhat中加入hardhat.config.js中加入如下代码即可。 出处https://github.com/lxdao-official/gclx-contracts/issues/2

const {setGlobalDispatcher,ProxyAgent} = require("undici")
const proxyAgent = new ProxyAgent('http://127.0.0.1:4780')
setGlobalDispatcher(proxyAgent)

例子:

require("dotenv").config();

//给验证合约设置代理
const {setGlobalDispatcher,ProxyAgent} = require("undici")
const proxyAgent = new ProxyAgent('http://127.0.0.1:4780')
setGlobalDispatcher(proxyAgent)

/** @type import('hardhat/config').HardhatUserConfig */

module.exports = {
  defaultNetwork: "goerli",
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY, // 在 etherscan 中设置 API 密钥
    // 增加超时时间(以毫秒为单位)
    timeout: 600000, // 设置为 10 分钟的超时
  },
  networks: {
    // 4. Add the Moonbase Alpha network specification
    goerli: {
      url: 'https://rpc.ankr.com/eth_goerli',
      chainId: 5,
      accounts: [process.env.BASE_GOERLI_PRIVATE_KEY]
    },
  },

  solidity: {
    version: "0.8.9",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },

};
你对 Hardhat 熟悉了吗 ? 测试你对 Hardhat 的了解,完成挑战领取 SBT ,为你的链上履历加上一笔 !
去挑战
点赞 1
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
志辉
志辉
江湖只有他的大名,没有他的介绍。