ERC20-解析Input-data java (transfer)

	
	    org.web3j
	    crypto
	    4.2.0
	

maven 引入
 

 

package *;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.web3j.abi.TypeDecoder;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.generated.Uint256;

public class TestWeb3j {

    public static void main(String[] args) {
        String inputData = "0xa9059cbb0000000000000000000000008e7e315fd8965b0fadc7c404307a55d5a6ccf15500000000000000000000000000000000000000000000000012f5dc3926dbd000";
        String method = inputData.substring(0, 10);
        System.out.println(method);
        String to = inputData.substring(10, 74);
        String value = inputData.substring(74);
        Method refMethod;
        try {
            refMethod = TypeDecoder.class.getDeclaredMethod("decode", String.class, int.class, Class.class);
            refMethod.setAccessible(true);
            Address address = (Address) refMethod.invoke(null, to, 0, Address.class);
            System.out.println(address.toString());
            Uint256 amount = (Uint256) refMethod.invoke(null, value, 0, Uint256.class);
            System.out.println(amount.getValue());
        } catch (NoSuchMethodException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

问题

https://github.com/web3j/web3j/issues/489

其他类似,当然要提前知道abi json

 

你可能感兴趣的:(区块链)