How can I find the followingin a block with web3.js

Viewed 90

I can't find any aggregation functions that do the following.

From the address that sent most transactions.

To address that received most transactions.

The transaction with the highest gas price

1 Answers

There aren't any. It is possible to iterate through the transaction list in a block and generate these data yourself, however:

function getBiggestSender(block) {
    let addressToNumTx = {};
    block.transactions.map(transaction => transaction.from).forEach(from => {
        if (!(from in mapping)) {
            addressToNumTx[from] = 0;
        }
        addressToNumTx[from]++;
    });
    let mostTxes = 0;
    let mostAddr = 0;
    for (from in mapping) {
        if (addressToNumTx[from] > mostTxes) {
            mostTxes = addressToNumTx[from];
            mostAddr = from;
        }
    }
    return mostAddr;
}

Other functions can be adapted from the above.

Related