I am trying to decode a String with this code that I found but I have not been able to do it.

String to = inputdata.substring(10, 74);
String value = inputdata.substring(74, 138);

Method refMethod = TypeDecoder.class.getDeclaredMethod("decode", String.class, int.class, Class.class);

String cadena = (String) refMethod.invoke(null, to, 0, String.class);
Uint256 amount = (Uint256) refMethod.invoke(null, value, 0, Uint256.class);

I can get uint256 but not the string


I guess you are trying to decode erc20 transfer method.

You must use the object org.web3j.abi.datatypes.Address rather than String.class.


final Address address = (Address) refMethod.invoke( null, to, 0, Address.class);

and address.toString() is the real recipient of the ERC20 transaction.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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