I need to look for a value in the data field of a transaction and to know which transactions contain the desired value. Let me explain with an example. In the data field of a transaction there is for example the variable username which has value "testusername". How can I search among all transactions only those that have the variable with username "testusername"? Do you know how I could do that?



I'm not sure if I understood it correctly, here is something you can try:

async function getCount() {
    // get block with transaction object
    let block = await web3.eth.getBlock(2535330, true);
    // get block transactions and loop through each transaction
    block.transactions.forEach(tx => {
        // log what is input actually
        // 0xd69f13bb0000000000000000000000004171b9e0267d09799a0d68e83cb0217988f9fe3a000000000000000000000000000000000000000000000000000000000026afa0
        // the end of above is value sent in the transaction
        // decode this value using web3.utils
        let value = tx.input.slice(tx.input.length - 6, tx.input.length)
        // covert this value to number
        let numValue = web3.utils.toDecimal("0x" + tx.input.slice(tx.input.length - 6, tx.input.length))

        // use if statement to filter it out
        if (value == '26afa0') {



hope it will help.

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.