如何解决在 send() 调用内的“options”对象中不包括“gas”或“gasPrice”属性
这是一个 web3 问题:有谁知道当您不指定 send()
或 gas
时,智能合约方法的 gasPrice
函数调用默认是什么?它会自动分配足够的gas并计算当前的平均gasPrice吗?这些属性总是可选的还是在某些情况下必须包含其中之一?
解决方法
从 documentation 来看,gas
和 gas
似乎总是可选的。
不幸的是,文档没有说明未提供时默认值是什么,但是在代码上有一个快速峰值(希望这是正确的代码路径)它似乎在内部调用 getGasPrice
来获取 gas价格,然后默认 gasPrice
为该价格。
// Send the actual transaction
if (isSendTx && _.isObject(payload.params[0]) && typeof payload.params[0].gasPrice === 'undefined') {
var getGasPrice = (new Method({
name: 'getGasPrice',call: 'eth_gasPrice',params: 0
})).createFunction(method.requestManager);
getGasPrice(function (err,gasPrice) {
if (gasPrice) {
payload.params[0].gasPrice = gasPrice;
}
if (isSendTx) {
setTimeout(() => {
defer.eventEmitter.emit('sending',payload);
},0);
}
sendRequest(payload,method);
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。