繁体   English   中英

在Web3j以太坊事务中设置十六进制编码的数据字段

[英]Setting the hex-encoded data field in a Web3j Ethereum transaction

我正在编写一个Web3j应用程序,我想进行资金转移,并在交易的十六进制编码数据字段中放入一个短文本字符串。 我已经成功转移了资金,但是似乎没有参数可以放入这些额外的数据。 我该怎么做呢?

一旦成功,我相信我可以通过查看

txObject.getInput();

(当然,这必须正确解码)这是正确的吗?

您可以使用事务的“数据”字段放入该短文本。 您必须编码为十六进制文本。 例如,如果要编写“ ABC”,则需要发送“ 0x414243”。 但是,这将花费您更多的汽油!

public EthSendTransaction sendTransaction(
        BigInteger gasPrice, BigInteger gasLimit, String to,
        String data, BigInteger value)
        throws IOException {

    Transaction transaction = new Transaction(
            getFromAddress(), null, gasPrice, gasLimit, to, value, data);

    return web3j.ethSendTransaction(transaction)
            .send();

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM