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.

Sep 28, 2018 in Blockchain by slayer
• 29,370 points
1,288 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,740 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
1,702 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
2,608 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,370 points
2,120 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
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
+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,610 points
1,414 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,740 points
3,503 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,740 points
644 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP