0

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);
refMethod.setAccessible(true);

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

I can get uint256 but not the string

0

I guess you are trying to decode erc20 transfer method.

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

Example:

final Address address = (Address) refMethod.invoke( null, to, 0, Address.class);
System.out.println(address.toString());

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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