我想知道下面的模式是否是正确的交易发送与正确的气体限制。
this.contracts.myContract.methods.myMethod.getEstimatedGas().then(gas => {
this.contracts.myContract.methods.myMethod.cacheSend(
["prop1", "prop2"],
{
gas
}
);
});我还读到,在估计的基础上增加10%是明智的。
或者,在进行方法调用时,我应该使用Metamask填充的任何价格吗?
发布于 2018-06-28 11:21:21
您可以使用web3.eth.estimateGas估算您的交易的气体成本。
示例:
var result = web3.eth.estimateGas({
to: "0xc4abd0339eb8d57087278718986382264244252f",
data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003"
});
console.log(result); // "0x0000000000000000000000000000000000000000000000000000000000000015为了安全起见,我会把这个估计数乘以1.1。
有关更多参考,请参见https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethestimategas。
发布于 2018-06-28 11:06:12
我经常遵循这样的模式,这应该是有用的:
await contractInstance.methods.transfer(self.state.owner, self.state.value)
.send({
from: accounts[0],
gas: '5000000'
})使用气体,您正在设置gasLimit。
https://ethereum.stackexchange.com/questions/52279
复制相似问题