Ethereum 估计气体始终为零或零
在使用web3时,我对以下内容有一些问题 可能是我的代码,也可能只是交易不需要汽油 始终返回null或零 可能是我的理解力不足,建议将不胜感激Ethereum 估计气体始终为零或零,ethereum,contract,web3,ether,metamask,Ethereum,Contract,Web3,Ether,Metamask,在使用web3时,我对以下内容有一些问题 可能是我的代码,也可能只是交易不需要汽油 始终返回null或零 可能是我的理解力不足,建议将不胜感激 var气体=0; const eth=新的eth(web3.currentProvider); 施工合同=新的eth合同(eth); const myContract=合同(abi); var me=myContract.at(合同地址); 估计气体({ 发件人:eth.账户[0], 致:“0x0Fe18f369c7F34208922cAEBbd5d2
var气体=0;
const eth=新的eth(web3.currentProvider);
施工合同=新的eth合同(eth);
const myContract=合同(abi);
var me=myContract.at(合同地址);
估计气体({
发件人:eth.账户[0],
致:“0x0Fe18f369c7F34208922cAEBbd5d21E131E44692”,
金额:web3.toWei(1,“乙醚”)},功能(d){
var gas=web3.toBigNumber(gas).toString();
控制台日志(气体);
if(gas.toString()!=“null”){
气体=d;
控制台日志(“气体:+d”);
}
});代码>
始终返回零。。。。还是空?这是我的代码错误吗?或者该交易不需要汽油??新的和学习的,谢谢。Web3 API使用
您的呼叫应如下所示:
eth.estimateGas({
from: eth.accounts[0],
to: "0x0Fe18f369c7F34208922cAEBbd5d21E131E44692",
value: web3.toWei(1, "ether")
},
function(e, d) {
var gas = web3.toBigNumber(gas).toString();
console.log(gas);
if (gas.toString() != "null") {
gas = d;
console.log("Gas: " + d);
}
});
哦,他妈的,谢谢你,所以从我能告诉你的是,它只是以零错误的形式发回null。。。。谢谢