I can not deploy my contract when I use estimateGas() actually estimateGas() and the gasUsed in error is the same. Why does this happen? How to fix this problem?
my code:
const deployedContract = await deployTx.send({
from: signer.address,
gas: await deployTx.estimateGas(),
}).once("transactionHash", (txhash) => {
console.log(`Mining deployment transaction ...`);
console.log(txhash);
});
error:
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: {}
}
}
There is no error in your code.
The contract has been successfully deployed to the address 0x2801...
shown in the contractAddress
property of the transaction receipt.
estimateGas()
just asks the node that you're connected to (in your case most likely a local emulator) to estimate how much gas is the transaction going to cost.