In myetherwallet, there is an +Advanced: Add Data Section where I can add data to the transaction.

How can I add this same data in a transaction I make in Solidity?

enter image description here


you need first to convert your string to the hexadecimal form using an online converter like http://string-functions.com/string-hex.aspx.

then put it in the data field (with 0x in the begining)

for example i've converted StackExchange into 0x537461636b45786368616e6765

enter image description here

put it in the data field and then i've send successfully my transaction. you could check the transaction here.

enter image description here

you could press the convert to asci button in the bottom to get back the encoded sent string.


You can use Solidity's low-level call, but be careful of What does `call.value` mean and how did it allow the attack to The DAO?


bytes calldata = 0xabcdef;
address to = 0x...
if (to.call(calldata)) {  // checks the return value
} else {

If you wanted to send along 2 ETH, the syntax would be:

to.call.value(2 * 10**18)(calldata);  // should check the return value

Some information in the Solidity docs and FAQ.

Whenever you use call, code in the to contract can be executed and since it can call you back in ways that you might not expect (like the TheDAO), one should follow guidelines such as updating state variables first and making call the very last step (an example that shows a state variable being set to zero first, and then a making a call to msg.sender).

  • why not to use send instead call? – Sig Touri Jun 6 '17 at 8:42
  • @SigTouri Yes send or transfer is better if that's all that's needed. The question was asking about adding data. – eth Jun 7 '17 at 1:19
  • @eth How does one do this with token contract? value() seems to expect ether. – nu everest Mar 9 '18 at 19:08
  • @nueverest Tokens work quite different: you invoke a transfer function on a token contract and specify recipient and amount of tokens. You're correct that value() should not be used. Be careful and test first. – eth Mar 11 '18 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.