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
• 27,620 points
87 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 66,880 points

Related Questions In Blockchain

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 64 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 26, 2018 in Blockchain by Johnathon
• 9,050 points
38 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
77 views
0 votes
1 answer
0 votes
1 answer

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

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
45 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 30 in Blockchain by Omkar
• 66,880 points
63 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.