如何在nodejs上运行HardHat脚本,以便您可以在不同端口上分配多个EVM链?

发布于 2025-01-28 17:30:04 字数 671 浏览 5 评论 0原文

我希望能够为我的系统上的一个提供更多的链条(以太坊,BSC等)。
HardHat Doc显示,如何分叉 1链 NPX HARDHAT节点 - fork https:// ...,效果很好。
但是我想通过 nodejs脚本以编程方式分叉。

当我尝试在下面的nodej上划分链条时,它不起作用。我该怎么办?

谢谢!


`hre.config.networks.networks = {
     hardhat: {
        forking: {
          url: http://localhost:8545
        },
    }
}     

await hre.network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: http://localhost:8545,
          chainId: chainObj.chain_id,
          blockNumber: blockNumber, 
        },
      },
    ],
});

`

I want to be able to fork more chains (ethereum, bsc, etc.) than just one on my system.

Hardhat doc shows, how to fork 1 chain npx hardhat node --fork https://... and it works fine.

But I would like to fork them programmatically on a Nodejs script.

When I try to fork a chain on NodeJs like below, it does not work. What can I do?

Thanks!

`hre.config.networks.networks = {
     hardhat: {
        forking: {
          url: http://localhost:8545
        },
    }
}     

await hre.network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: http://localhost:8545,
          chainId: chainObj.chain_id,
          blockNumber: blockNumber, 
        },
      },
    ],
});

`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2025-02-04 17:30:04

也许会有所帮助。

hardhat.config.ts:

networks: {
    hardhat: {
        mining: {
            auto: false,
            interval: [10000, 10000],
        },
        chainId: Number(process.env.CHAIN_ID),
        forking: {
            url: process.env.NETWORK_URL || "",
            // blockNumber: Number(process.env.FROM_BLOCK) || 228,
        },
        accounts: [
            {
                balance: "100000000000000000000000000000",
                privateKey: process.env.PRIVATE_KEY as string,
            },
        ],
    }
}

package.json:

"scripts": {
"bsc": "NETWORK=bsc NETWORK_URL=https://rpc.ankr.com/bsc FROM_BLOCK=22828104 CHAIN_ID=100 npx hardhat node --port 8541 ",
"eth": "NETWORK=eth NETWORK_URL=https://rpc.ankr.com/eth FROM_BLOCK=15720107 CHAIN_ID=101 npx hardhat node --port 8542 ",
"avax": "NETWORK=avax NETWORK_URL=https://api.avax.network/ext/bc/C/rpc CHAIN_ID=102 FROM_BLOCK=20899475 npx hardhat node --port 8543 ",
"ftm": "NETWORK=ftm NETWORK_URL=https://rpc.ankr.com/fantom CHAIN_ID=103 FROM_BLOCK=48883683 npx hardhat node --port 8544 ",
}

Maybe it would help.

hardhat.config.ts:

networks: {
    hardhat: {
        mining: {
            auto: false,
            interval: [10000, 10000],
        },
        chainId: Number(process.env.CHAIN_ID),
        forking: {
            url: process.env.NETWORK_URL || "",
            // blockNumber: Number(process.env.FROM_BLOCK) || 228,
        },
        accounts: [
            {
                balance: "100000000000000000000000000000",
                privateKey: process.env.PRIVATE_KEY as string,
            },
        ],
    }
}

package.json:

"scripts": {
"bsc": "NETWORK=bsc NETWORK_URL=https://rpc.ankr.com/bsc FROM_BLOCK=22828104 CHAIN_ID=100 npx hardhat node --port 8541 ",
"eth": "NETWORK=eth NETWORK_URL=https://rpc.ankr.com/eth FROM_BLOCK=15720107 CHAIN_ID=101 npx hardhat node --port 8542 ",
"avax": "NETWORK=avax NETWORK_URL=https://api.avax.network/ext/bc/C/rpc CHAIN_ID=102 FROM_BLOCK=20899475 npx hardhat node --port 8543 ",
"ftm": "NETWORK=ftm NETWORK_URL=https://rpc.ankr.com/fantom CHAIN_ID=103 FROM_BLOCK=48883683 npx hardhat node --port 8544 ",
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文