天天看点

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

是的。文本应该是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帖子

对于理解这个问题很有用。

原文《Java以太坊类库web3j官网中文翻译》中的:

http://cw.hubwiz.com/card/c/web3j/1/12/6/

另外推荐几个很受欢迎全网稀缺的互动教程:

  • web3j ,主要是针对java和android程序员围绕web3j库进行区块链以太坊开发的讲解。
  • python以太坊 ,主要是针对python围绕web3.py进行区块链以太坊应用开发的讲解。
  • php以太坊 ,主要是介绍使用php进行智能合约开发交互,进行账号创建、交易、转账、代币开发以及过滤器和事件等内容。
  • 以太坊开发 ,主要是介绍使用node.js、mongodb、区块链、ipfs实现去中心化电商DApp实战,适合进阶。
  • 以太坊教程 ,主要介绍智能合约与dapp应用开发,适合入门。