是否可以用交易发送任意文本?

优质
小牛编辑
114浏览
2023-12-01

是否可以用交易发送任意文本?

是的。文本应该是ASCII编码的,并在交易的数据中以十六进制字符串的形式提供。示例如下:

RawTransaction.createTransaction(
        <nonce>, GAS_PRICE, GAS_LIMIT, "0x<address>", <amount>, "0x<hex encoded text>");

byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
String hexValue = Numeric.toHexString(signedMessage);

EthSendTransaction ethSendTransaction =
        web3j.ethSendRawTransaction(hexValue).send();
String transactionHash = ethSendTransaction.getTransactionHash();
...

:请确保你增加了交易的气体限制,以允许存储文本。

下面的stackexchange帖子对于理解这个问题很有用。