Help me, please, with this little simple task! I cannot solve this problem for several days. SOS! ;) I'm trying to write a program for filtering events via web3j. I copied to start (for the test) from somewhere this simple contract:

pragma solidity ^0.4.11;
contract EventTest {                
  event NumberEvent(uint indexed number);   

  function triggerEvent(uint val) returns (uint) { 
    return 123;

Then I ran TestRPC, Remix, and created a contract. Here is the state after that:

EthereumJS TestRPC v3.0.5

Available Accounts
(0) 0x5403bdee62d577b2660a2a6af4590ce9c426aceb
(1) 0x88302f871bb26f044f106f1f686fba4f07d9658d
(2) 0xd90aedb12243b420b63317936acaff289316bad6
(3) 0x537598e72b2b8cd179f3fc72ef09f7233f73ef44
(4) 0xef571d65c0e828da5091bb76169dc7ca0ff67f15
(5) 0xe251fa32bf822ad3ccb3133d97ccd64ab97cb0fd
(6) 0x20d6a6bd42ba577a1e6fa938f738b0e07191021b
(7) 0x8e76d16288f5068d2406f1cb7005df449a88790a
(8) 0xb05b5df33972324edc49c02d23ec710f31fc3d09
(9) 0x1bb116bd5916ba749caa429d08406d57030d2eb6

Private Keys
(0) fbd2033e842b85c0da50d1ebc0a73deae130c887762116937ad60266a974c3dd
(1) 6fa1c314f48bb9dee169cb3d6e4d9348adb7df82fefa5229349e8aa3ebc7ce02
(2) 0995cc564f136217a7438daab9f55ca3e593e67483f36de5862826b52f264b19
(3) f642805c48f3c9fda4fac90df031ad0836a4701263d1c900f1d5b42e3b073b51
(4) d4b868c78ee8af1c7900a9a2f6ae59042ef26038aeb151f03a010547852bc99a
(5) 9f76d96f9d88e078591f38ae0d249a746287814fb0f95e59b8634165a1b71560
(6) 722f6fbbd74b471e0ab294983401abb1aecabd6e1e4584eba99c2f408b75c9e3
(7) a57e22386e8874834535e2dd02c28ef8123e7412ff6896d273e0cac69553fe81
(8) 28a53adc37ffa7e96615b0b2e20fb7f342dc99aed2d0e681ca9a447cc5101f05
(9) b92a329c6f616af0bfe7f20d9a48e5518d5ede352475eab640a555300029a7d9

HD Wallet
Mnemonic:      bird ship unlock fiber drink kiwi surprise warrior over cereal item poet
Base HD Path:  m/44'/60'/0'/0/{account_index}

Listening on localhost:8545

  Transaction: 0xc9b39a4ee3c3d02ef4a76011b3bdc00721f196e90e6b9a6708c8d9842ca03698
  Contract created: 0x53417664007120b53005a9f1a42b3fb02e6cb0c7
  Gas usage: 0x01a9f1
  Block Number: 0x01
  Block Time: Thu May 04 2017 12:08:19 GMT+0200


Since in the command line from TestRPC approximately every second the message "eth_getFilterChanges" appeared, I closed the browser with Remix and then the new messages "eth_getFilterChanges" ceased to arrive.

Then I launched such Java code to "listen" to new events from this my test contract.

import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.http.HttpService;

import rx.functions.Action1;

public class Subscribe {

    public static String contractAddr = "0x53417664007120b53005a9f1a42b3fb02e6cb0c7";

    public static void main(String[] args) {

        Web3j web3 = Web3j.build(new HttpService());

        EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contractAddr);
        web3.ethLogObservable(filter).subscribe(new Action1<Log>() {
            public void call(Log log) {
                System.out.println("log.toString(): " + log.toString());

Here is the result:

FilterSubprovider - no filter with that id: 0x2

Could you please explain what I'm doing wrong? Thank you in advance for any help!

  • How are you calling the function triggerEvent? – arseniy May 4 '17 at 13:14
  • These messages appear BEFORE and REGARDLESS the event is called! – lfrickel May 5 '17 at 14:36

The problem here seems to be that test rpc doesn't recognize hex-numbers without the leading zero for single digit filters. So it recognizes "0x03" but not "0x3". And well that sucks.

But if you create and discard the first 9 filter ids you should be good to go with testrpc.

|improve this answer|||||

To call the event (for test) , I used, for example, this code:

import java.math.BigInteger;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;

import org.web3j.abi.FunctionEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Uint;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.http.HttpService;

public class SendEvent {

    public static String myAddr = "0x5638ebd0c2519a0a5e11b79c63add6ef1a5e0557";

    public static void main(String[] args) {

        try {
            Web3j web3 = Web3j.build(new HttpService());

            String encodedFunction = FunctionEncoder.encode(new Function("triggerEvent", 
                    Arrays.asList(new TypeReference<Uint>() {})));
            String from = myAddr;
            BigInteger gasPrice = BigInteger.valueOf(1);
            BigInteger gasLimit = BigInteger.valueOf(1000000L);
            String to = Subscribe.contractAddr;
            BigInteger nonce = null;

            Transaction transaction = Transaction.createFunctionCallTransaction(from, nonce, gasPrice, gasLimit, to,

            org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse = web3

        } catch (InterruptedException e) {
        } catch (ExecutionException e) {
|improve this answer|||||

I found this problem. This was in the test chain KOVAN and in TestRPC. The same actions on the main chain caused a successful result. I did not want to burden the main chain with test contracts, but I had to. Thank you all again!

The contrakt: 0x2783318E7C1c6d1Aab46F0773264f74Fd0a8313d

|improve this answer|||||

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.