1

I trying to listen events from smart contract but my code isn't working. what's the problem?

Event event = droneChain.UPDATEMISSIONSTATE_EVENT;
String encodedEventSignature = EventEncoder.encode(event);
EthFilter filter = new EthFilter(DefaultBlockParameterName.LATEST, DefaultBlockParameterName.LATEST,contractAddr).addSingleTopic(encodedEventSignature);
droneChain.updateMissionStateEventObservable(filter).subscribe(updateMissionStateEventResponse -> {Toast.makeText(MapsActivity.this, updateMissionStateEventResponse._from, Toast.LENGTH_SHORT);
},Throwable::printStackTrace);

here is my code.

any body help me

1 Answer 1

0

You should call ethLogFlowable after filter definition as follow:

web3j.ethLogFlowable(filter).subscribe(log -> {
            System.out.println("Event log: "+log);
            List<Type> params = FunctionReturnDecoder.decode(
                    log.getData(), my_event.getParameters());
            System.out.println("Event param 0: "+params.get(0).getValue()); ...

        });

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.