1

I am new in ethereum, I just run simple node.js program and using web3 api, and I send some ether from my account to another in my private ethereum network, after mining my transactions mined. I still have some pending transactions, my problem is that when I want to get the number of pending transactions by following code it has the error:

Cannot read property 'length' of undefined

, howeverو I can query the pending transactions numbers via geth javascript console by this query: eth.pendingTransactions.length

console.log(web3.eth.pendingTransactions.length);

Also, I used getPendingTransactions function with call back but still it has the same error.

I checked for some other functions and variables it works fine I do not know what is the problem with array of pendingTransaction and function getPendingTransactions.

Here is my simple code:

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8000'));
console.log(web3.version.api);
var hashstring = web3.eth.sendTransaction({from: "X", to: "Y", value: web3.toWei(10, 'ether'),gas:30000});
console.log(hashstring);
console.log(web3.eth.pendingTransactions.length);
  • Maybe helpful if you post your actual failing code? – Edmund Edgar Jan 23 '17 at 0:55
  • I just moved the code into the question for clarity. – Rob Hitchens - B9lab Jan 23 '17 at 1:52
1

web3.eth.pendingTransactions seems to be a Geth internal addition, I do not see it in the JSON-RPC or Web3 standard.

You are probably better off using this:

web3.eth.getBlock(
    "pending",
    function (error, block) {
        if (error) {
            console.error(error);
        } else {
            console.log(block.transactions.length); 
        }
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.