Created
August 20, 2024 18:50
-
-
Save jcortejoso/734044fe338c72c2caee9ba18a368398 to your computer and use it in GitHub Desktop.
Get Average Transaction Size Geth console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getAverageTransactionSize() { | |
| var days = 90; | |
| var sampleSize = 50000; | |
| var lastBlock = eth.blockNumber; | |
| var firstBlock = lastBlock - Math.floor(days * 24 * 60 * 60 / 5); // Assuming 5 seconds per block | |
| var totalAverageTransactionSize = 0; | |
| for (var i = 0; i < sampleSize; i++) { | |
| var blockNumber = Math.floor(Math.random() * (lastBlock - firstBlock + 1)) + firstBlock; | |
| var block = eth.getBlock(blockNumber); | |
| if (!block || !block.transactions) continue; | |
| var transactions = block.transactions; | |
| var totalBlockSize = 0; | |
| for (var j = 0; j < transactions.length; j++) { | |
| var transactionSize = eth.getRawTransaction(transactions[j]); | |
| totalBlockSize += transactionSize.length; | |
| } | |
| if (transactions.length > 0) { | |
| totalAverageTransactionSize += totalBlockSize / transactions.length; | |
| } | |
| } | |
| var averageTransactionSize = totalAverageTransactionSize / sampleSize; | |
| console.log('Average transaction size for the last ' + days + ' days is ' + averageTransactionSize + ' bytes (sample size: ' + sampleSize + ')'); | |
| } | |
| // Call the function to execute it | |
| getAverageTransactionSize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment