ERC 20 - 분석 입력 데이터 자바 (transfer)

2078 단어 블록 체인
	
	    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 을 미리 알 아야 한다.

좋은 웹페이지 즐겨찾기