在 send() 调用内的 'options' 对象中不包括 'gas' 或 'gasPrice' 属性
Not including 'gas' or 'gasPrice' attributes in the 'options' object inside of a send() call
这是一个 web3 问题:有谁知道当您没有指定 gas
或 gasPrice
时,对智能合约方法的 send()
函数调用默认是什么?它是否自动分配足够的gas并计算当前的平均gasPrice?这些属性总是可选的还是在某些情况下必须包含其中任何一个?
从 documentation 开始,gas
和 gas
似乎总是可选的。
不幸的是,文档没有说明那些在没有提供时默认的内容,但是快速了解代码(希望这是正确的代码路径)似乎它在内部调用 getGasPrice
来获取汽油价格,然后将 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);
});
这是一个 web3 问题:有谁知道当您没有指定 gas
或 gasPrice
时,对智能合约方法的 send()
函数调用默认是什么?它是否自动分配足够的gas并计算当前的平均gasPrice?这些属性总是可选的还是在某些情况下必须包含其中任何一个?
从 documentation 开始,gas
和 gas
似乎总是可选的。
不幸的是,文档没有说明那些在没有提供时默认的内容,但是快速了解代码(希望这是正确的代码路径)似乎它在内部调用 getGasPrice
来获取汽油价格,然后将 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);
});