I'm having trouble trying to create a simple contract that "just log" to the blockchain what is being sent from a java client. The transaction executing the log looks to be correct (how can I be sure about it?) but I find no way to retrieve the logs from the java client:

The smart-contract looks similar to:

pragma solidity ^0.4.2;

contract MyLogContract {
    event genericLog(
        uint256 indexed _index1, uint256 indexed _index2,  uint256 indexed _index3, string _log);

    function writeGenericLog01(
        uint256 _index1, uint256 _index2,  uint256 _index3,
        string _log) 
    returns (bool success) {
        genericLog(_index1, _index2, _index3, _log);
        return true;

The java code looks similar to (userWrapper4Logs => use java wrapper, otherwise use hand-made transaction):

TransactionReceipt receipt;
if (!userWrapper4Logs){
     String encodedFunction = FunctionEncoder.encode(
         new Function("writeGenericLog01", 
                 Uint256.DEFAULT, Uint256.DEFAULT, 
                 new Utf8String("Best log in Town!")) ,
              Arrays.asList(new TypeReference<Uint256>() {} )
     String from = ownerAddress;
     BigInteger gasPrice = BigInteger.valueOf(1),
                gasLimit = BigInteger.valueOf(1000000L);
                nonce = null; // <- Ummm?
     String to = bc.listenerAPI_contractAddress;
     Transaction transaction = Transaction.
             from, nonce, gasPrice, gasLimit, to, encodedFunction);

     Optional<TransactionReceipt> transactionResponse = 

     receipt =  transactionResponse.get();
if (userWrapper4Logs) {
    MyLogContract wrapper = getContract(contractAddress, owner);
    receipt =  wrapper.writeGenericLog01(
             new Utf8String("Best log in the wild wild West!")

System.out.println( ""
       + "\n BlockNumber()        : " + receipt.getBlockNumber()
       + "\n Cumulativ eGasUsed() : " + receipt.getCumulativeGasUsed()
       + "\n Log size             : " + receipt.getLogs().size() );

The transaction looks to execute properly and after mining 5 blocks the receipt is returned. Nothingness the log size is always zero. The STDOUT output looks similar to:

BlockNumber()        : 2528
Cumulativ eGasUsed() : 22872
Log size             : 0

I have some doubts about whether testrpc is able to handle log transactions or maybe they are just discarded by this sort of javascript node simulator, so I also tested with a real geth using next parameters (maybe something else is also needed):

$ geth --verbosity 4 --dev --maxpeers 0 --nodiscover --rpc --rpcaddr --networkid 1500 --mine --fakepow --minerthreads=1 --etherbase=0x......

(I also tried without the --dev option but then transaction looks to be never confirmed).

Thanks in advance for any help/hint or link!

Update 201-05-09: I tested the same contract with Truffle/web3js and logs are detected properly by the client, even using testrpc (only restricted to setup the event listener before submitting the transaction).

1 Answer 1


It was due to a bug in the Filter.java class. The commit with the patch is available at: https://github.com/earizon/web3j/commit/d0e641a4905f2900924df448d9b132d0bb34e4b0

I let a pull request on the main branch: https://github.com/web3j/web3j/pull/115

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.