web3j icon indicating copy to clipboard operation
web3j copied to clipboard

How do I get topics content?

Open fastener opened this issue 4 years ago • 1 comments

I get the topics in logs through transactionreceive. Getlogs(), but the topics content is a hexadecimal string. How can I convert the hexadecimal string into a plaintext string to see the real content of topics, Like https://etherscan.io/tx/0xe08975859bc8ef5a6a9fa0ddae51a59b3745789fe80124b80bd715a65a491153 The inputdata displayed here is the same as the plaintext。 What method should I use to parse?

fastener avatar Dec 02 '21 15:12 fastener

public static final String topicNTCreated= EventEncoder.encode(NTContract.NTCREATED_EVENT);

if (log.getAddress().equalsIgnoreCase(ntContract.getContractAddress()) && log.getTopics().get(0).equals(topicNTCreated)) {
  logger.info("Found nt created event log.");
  EventValues values = NTContract.staticExtractEventParameters(NTContract.NTCREATED_EVENT,
	  log);
  NTEventResponse typedResponse = new NTEventResponse();
  typedResponse.log = log;
  typedResponse.tokenId = (BigInteger) values.getNonIndexedValues().get(0).getValue();
  typedResponse.start = (BigInteger) values.getNonIndexedValues().get(1).getValue();
  typedResponse.end = (BigInteger) values.getNonIndexedValues().get(2).getValue();
  typedResponse.duration = (BigInteger) values.getNonIndexedValues().get(3).getValue();
  processNTCreated(typedResponse);
}

You can find the return data similar to the NTEventResponse in the generated contract code, and you can find the method of how to obtain parameters from the code,The processNTCreated method handles subsequent business.

kutasms avatar Jan 26 '22 20:01 kutasms