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

志辉 发布于 2023-09-02 阅读 4791

在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 熟悉了吗 ? 测试你对 Hardhat 的了解,完成挑战领取 SBT ,为你的链上履历加上一笔 ! 去挑战

相关文章

0 条评论