Why estimateGas always returns null or zero?

0 votes

Playing with web3, i am having some issue with the following.

Always returns null or Zero.

var gas = 0; 

const eth = new Eth(web3.currentProvider); 

const contract = new EthContract(eth); 

const myContract= contract(abi); 

var me = myContract.at(contractAddress); 

eth.estimateGas({

     from: eth.accounts[0], to: "0x0Fe18f369c7F34208922cAEBbd5d21E131E44692", 

     amount: web3.toWei(1, "ether")}, 

     function(d){ 

     var gas = web3.toBigNumber(gas).toString(); 

     console.log(gas);
     if(gas.toString() != "null")

     { gas = d; console.log("Gas: " + d); } });

Returns zero always.... or null? This is error with my code? or this transaction requires no gas ?? New and learning, thanks.

ethereum contract web3 ether metamask

Sep 28, 2018 in Blockchain by slayer
• 29,170 points
67 views

1 answer to this question.

0 votes

The Web3 API uses error first style callbacks.

Your call should look like this:

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);
    }
 });
answered Sep 28, 2018 by digger
• 26,550 points

Related Questions In Blockchain

0 votes
1 answer

GetState query via chaincode always returns empty value

fabric uses an ccenv image to build the chaincode when ...READ MORE

answered Jul 17, 2018 in Blockchain by Christine
• 15,790 points
368 views
0 votes
1 answer

eth.getBalance() always returns 0 in testnet

You are not connecting to the right ...READ MORE

answered Jul 24, 2018 in Blockchain by Christine
• 15,790 points
505 views
0 votes
1 answer

eth.getTransactionReceipt returns null

It looks like there's an issue with ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,170 points
250 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
159 views
0 votes
1 answer
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,620 points
144 views
0 votes
1 answer

var_dump of a JSON response returns NULL

You should be aware of the chances ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,550 points
387 views
0 votes
1 answer

Why is Nubits faster than Bitcoin?

Different implementation of blockchain can have different ...READ MORE

answered Jul 11, 2018 in Blockchain by digger
• 26,550 points
23 views