How to set the hex-encoded data field in a Web3j Ethereum transaction

0 votes

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

Is this correct?

Oct 15, 2018 in Blockchain by digger
• 26,740 points
3,019 views

1 answer to this question.

0 votes

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

}

answered Oct 15, 2018 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
0 answers
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,594 views
+1 vote
1 answer

How does a miner get to know that a transaction is verified by all the nodes?

Contrary to the popular belief, it is ...READ MORE

answered Mar 27, 2018 in Blockchain by Johnathon
• 9,090 points
2,872 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,947 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,471 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,461 views
0 votes
1 answer

How many peers in fabric network need to endorse a transaction?

The number of peers required to endorse ...READ MORE

answered Jan 31, 2019 in Blockchain by Omkar
• 69,220 points
2,369 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP