0

I'm writing a Web3j app and I'd like to perform a transfer of funds and put a short text string in the hex-encoded data field of the transaction. I'm successfully transferring the funds, but there doesn't seem to be a parameter to put this extra data. How do I do this?

Once this works, I believe that I can see my string by looking at

txObject.getInput();

(of course, this has to be properly decoded) Is this correct?

Sander Smith
  • 1,371
  • 4
  • 20
  • 30

1 Answers1

0

You can use the "data" field of a transaction to put that short text. You have to encode to hex your text. For example if you want to write "ABC" you need to send "0x414243". This will cost you more gas, though!

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();

}