I want to get the name of an emitted event from my contract using the event abi and web3j.

This is the contract i'm using as an example for this question:

pragma solidity ^0.5.7;
contract NumberContract2{

uint256 number;

event newNumberStored(uint256 number);
event calledRequestNumberFunction();

function storeNumber(uint256 num) public
    number = num;
    emit newNumberStored(num);

function requestNumber() public returns (uint256)
    emit calledRequestNumberFunction();
    return number;


This is where i hope to get the information out of (see event abi):


I created a listener in my code that prints out every event that gets emitted:

EthFilter filter = new EthFilter(DefaultBlockParameterName.LATEST, DefaultBlockParameterName.LATEST, numberContract2.getContractAddress().substring(2));
    web3j.ethLogFlowable(filter).subscribe(log -> System.out.println(log));

When an event is emitted (in this case through storeNumber(1234)) it prints out the following:

Log{removed=false, logIndex='0x0', transactionIndex='0x0', transactionHash='0xde7ea1ed3ca6cae5e3fb2478cc0212a2fc4d71c4c82b2edabde61c88629f667c', blockHash='0xb86c2af91b32492ee06e7ca632a56b973dfb5bbb4af045c627727547819c298f', blockNumber='0x89', address='0x820dbe91d4ee217b518b7be2cd7c30ea47e5ee1e', data='0x00000000000000000000000000000000000000000000000000000000000004d2', type='mined', topics=[0xa7f1c945da9b165cf9d2d173e7bf823eb59569ecffef3d150fe6c74b6e78933f]}

Which is kind of what i expected, but how can i get the name of the event now? Is it even possible? If not is there another way to do it?

When i look at the transaction log in remix it clearly shows the name of the event but i don't see that in the log that i print out.

    [ { "from": "0x820Dbe91D4Ee217B518B7BE2CD7c30ea47e5ee1E", "topic": "0xa7f1c945da9b165cf9d2d173e7bf823eb59569ecffef3d150fe6c74b6e78933f", "event": "newNumberStored", "args": { "0": "1234", "number": "1234" } } ]

My goal in the end is to add a listener that listens to all events, and filter them by name later (outside of web3j).

Your Answer

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

Browse other questions tagged or ask your own question.