10 hardhat fork 问题

hardhat fork 16000000 运行为什么会是在16000002 还有为什么没有gasused字段

测试代码:

describe("test", function () {
  async function dodeploy() {
    const Tra = await ethers.getContractFactory("tra");
    const tra = await Tra.deploy();    
    await tra.deployed();
  }
  describe("do",async function(){
    it("do",async function(){
      const myContract = await loadFixture(dodeploy);
      const [owner] = await ethers.getSigners();
      var tc = await network.provider.request({
          method: "eth_getTransactionCount",
          params: [owner.address],
        });    

        var rawTx = {
          nonce: tc,
          gasPrice: 20787108203,
          gasLimit: 200000,
          to: myContract.address,
          value: 0x00,
          data: "0xd0c2863a"
        }

        var tx = new Tx(rawTx);
        tx.sign(privateKey);
        var serializedTx = tx.serialize();
        const par = '0x' + serializedTx.toString('hex');  
        var tran = await network.provider.request({
          method: "eth_sendRawTransaction",
          params: [par],
        });    
        const tif = await ethers.provider.getTransaction(tran)
        console.log(tif);
    })
  });

});

c83ddaee7b6903c817e82f08eb26fda.png

hardhat.config.js 配置:

module.exports = {
  solidity: "0.8.18",
  settings: {
    optimizer: {
      enabled: true,
      runs: 1000
    }
  },
  networks: {
    hardhat: {
      chainId: 31337,//默认链id
      forking: {
        url: "https://eth-mainnet.nodereal.io/v1/1659dfb40aa24bbb8153a677b98064d7",
        blockNumber: 16000000
      }
    }
  }  
};
请先 登录 后评论

最佳答案 2023-04-05 09:14

会自动挖矿吧,可以找文档看下; gasused 在 getTransactionReceipt

请先 登录 后评论

其它 1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,1500 浏览
  • 用户_12760 提出于 2023-04-04 17:26