I am trying to find the number of transactions in the Ethereum network using web3. I couldn't find any web3 functions to get the same.

I could see etherchain.org and some other network browsers have implemented the same. I tried to dig into their codes and found nothing useful. Found another thread on the same topic Where can I find transactions per second statistics? saying divide the number of transactions per day and the number of seconds per day, but wondering how to find the number of transactions per day.

up vote 0 down vote accepted

You can find the daily transaction from http://etherscan.io/chart/tx . Right mouse click and view source, and you will find the following type of data:

data: [ {y : 8893, dt : 'Thursday, July 30, 2015', difficulty : '0.121 TH', estHashrate : '23.7569 GH', blockTime : '4', blockSize : '644', blockCount : '6912', unclesCount : '1299', newaddress : '9205'  },
...
,{y : 42581, dt : 'Sunday, June 12, 2016', difficulty : '47.368 TH', estHashrate : '3454.4512 GH', blockTime : '14', blockSize : '1463', blockCount : '6064', unclesCount : '468', newaddress : '2117'  },
    ]

42,581 is the number of transactions for Sunday June 12, 2016.

If you want to try and find the transactions in each block, you can use this script in Common useful JavaScript snippets for geth .

You will see in the script that to find a block, use

var block = eth.getBlock(i, true);

And to find the list of transactions in the block, use

if (block != null && block.transactions != null) {
  block.transactions.forEach( function(e) {
    if (myaccount == "*" || myaccount == e.from || myaccount == e.to) {
      console.log("  tx hash          : " + e.hash + "\n"
        + "   nonce           : " + e.nonce + "\n"
        + "   blockHash       : " + e.blockHash + "\n"
        + "   blockNumber     : " + e.blockNumber + "\n"
        + "   transactionIndex: " + e.transactionIndex + "\n"
        + "   from            : " + e.from + "\n" 
        + "   to              : " + e.to + "\n"
        + "   value           : " + e.value + "\n"
        + "   gasPrice        : " + e.gasPrice + "\n"
        + "   gas             : " + e.gas + "\n"
        + "   input           : " + e.input);
    }
  })
}

The block timestamp will be in:

block.timestamp

Here's some sample geth JavaScript code to get your data:

> var i;
undefined
> for (i = 1696781; i < 1696785; i++) {
.. var block = eth.getBlock(i);
.. if (block != null && block.transactions != null) {
...... console.log(i + " " + block.timestamp + " " + block.transactions.length);
...... }
.. }
1696781 1465823661 6
1696782 1465823697 8
1696783 1465823704 5
1696784 1465823718 7
undefined

The block.timestamp field is a Unix timestamp, so 1465823718 = GMT: Mon, 13 Jun 2016 13:25:16 GMT.

You can also try using the JavaScript API - web3.eth.getBlockTransactionCount function:

> var i;
undefined
> for (i = 1696781; i < 1696785; i++) {
.. var block = eth.getBlock(i);
.. var txcount = eth.getBlockTransactionCount(i);
.. console.log(i + " " + block.timestamp + " " + txcount);
.. }
1696781 1465823661 6
1696782 1465823697 8
1696783 1465823704 5
1696784 1465823718 7
undefined

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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