使用 estimateGas() 时无法部署我的合约

Can not deploy my contract when i use estimateGas()

当我使用estimateGas()时无法部署我的合约,实际上estimateGas()和错误的gasUsed是一样的。为什么会这样?如何解决这个问题?

我的代码:

const deployedContract = await deployTx.send({
            from: signer.address,
            gas: await deployTx.estimateGas(),
        }).once("transactionHash", (txhash) => {
            console.log(`Mining deployment transaction ...`);
            console.log(txhash);
        });

错误:

  receipt: {
    blockHash: '0x6330753afbeae8ac63fc4056d9f26ea8eec15cfcf6a4cfcf34f4fd2ada55620c',
    blockNumber: 10781483,
    contractAddress: '0x2801e146eB41339F060BbF2b2dd87cE970e5cAec',
    cumulativeGasUsed: 5421372,
    effectiveGasPrice: 4154546093,
    from: '0xa458b7e161aa47c268053004fd0b25b7a2fa66f0',
    gasUsed: 2442757,
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: false,
    to: null,
    transactionHash: '0x9e5f0d788ce28e3f5d35ee80e911d3f23f984d3d7d98271e82582b6045534acc',
    transactionIndex: 11,
    type: '0x2',
    events: {}
  }
}

你的代码没有错误。

合约已成功部署到交易收据contractAddress属性中显示的地址0x2801...

estimateGas() 只是询问您连接到的节点(在您的情况下很可能是本地模拟器)来估计交易将花费多少 gas。