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?
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
put it in the data field and then i've send successfully my transaction. you could check the transaction 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?
Example:
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).
send
or transfer
is better if that's all that's needed. The question was asking about adding data.