3

我在 java 中使用 web3j 来获取交易的输入数据。我可以获得数据,但问题是如何解码这些数据。

Input data: "0x070ec83b000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000015118f200000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000.........."

String inputdata = null;

Optional<Transaction> tx = web3.ethGetTransactionByHash(txHash).send().getTransaction();

if (tx.isPresent()) {
    inputdata = tx.get().getInput();
}

//DECODE

byte[] bytes = Hex.decodeHex(inputdata.substring(2).toCharArray());
System.out.println(new String(bytes, "UTF-8"));

当你执行代码时,你得到的是各种字符。

输出

4

1 回答 1

0

我不精通nodeJS,但这里是如何在python中做到这一点,以防万一。

txn = web3.eth.get_transaction(txHash)                                  
txnInput = routerContract.decode_function_input(txn.input) 
print(txnInput)
于 2021-11-04T19:12:52.600 回答