Web3j: web3j.transactionObservable() listened a transaction twice

Created on 21 Mar 2018  路  5Comments  路  Source: web3j/web3j

web3j.transactionObservable() .subscribe listened a transaction(same tx hash) twice with different block number.
It there a bug or another problem?
Anyone can help me,I'll appreciate.
Thanks

Most helpful comment

@Jesse0722 web3j.transactionObservable() do not work in my project,
can you give me a example? please

All 5 comments

@Jesse0722 web3j.transactionObservable() do not work in my project,
can you give me a example? please

@Jesse0722 I guess this can happen in case the same transaction was included in blocks generated by different miners.

when I subcribe a blcokevent ,it doesn't work.
Subscription subscription = web3j.blockObservable(false).subscribe(block -> {
EthBlock.Block block1 = block.getBlock();
System.out.println("GasLimit:" + block1.getGasLimit());
System.out.println("GasLimitRaw:" + block1.getGasLimitRaw());
System.out.println("GasUsed:" + block1.getGasUsed());
System.out.println("GasUsedRa:" + block1.getGasUsedRaw());
System.out.println("Hash:" + block1.getHash());
System.out.println("Nonce:" + block1.getNonce());
System.out.println("Nonce:" + block1.getNonce());
List transactions = block1.getTransactions();
System.out.println("transactions.size:" + transactions.size());
});

I'm experiencing the same behavior with blocks with web3j.blockObservable(). I frequently get blocks with the same number twice. Is this normal? If so, how should I handle these situations?

It's normal. As @fcorneli said, the transaction was included in blocks generated by different miners. You can listened the transaction both of them, but the first one usually is useless, called uncle block.
You can synchronize the transaction from block, one by one, and behind several blocks of the hightest block, instead of observing them.
Use web3j.ethGetBlockByNumber to get block, and analysis transaction.

Was this page helpful?
0 / 5 - 0 ratings