1

Smart contracts can obviously send transactions through the Ethereum network but can they also send a simple message along with the transaction?

Usaully you would put the message into hex code in the "data" field but how do you make a smart contract do that?

Thanks.

3 Answers 3

3

I'm assuming you would like to send a message along with a transaction that goes to a "normal" account, not a "smart contract" account. Maybe even from a "normal" account as well.

What you can do is convert your text message to hex, using any online converter, for example this one.

Most wallets have a data field for a transaction, where you then paste the hex. From within a contract, you would have to use the call method, as described here.

For example, a message like "3 o'clock at the tower" converts to "0x33206f27636c6f636b2061742074686520746f776572", which you send along in the "data" field.

If the receiver does not get these data in their wallet, they will have to look it up the transaction on the blockchain explorer like etherscan, scroll down and find the field Input Data, where your hex string will be displayed.

Be sure that the receiver know how to convert this back. They could use an online hex to text converter like this one.

4
  • Could you reverse code hex? So could you just make the hex code display normal letters?
    – Cryptic
    Commented Sep 2, 2019 at 5:58
  • @Cryptic Hi, not sure I understand your question. The hex code in my answer converts to "3 o'clock at the tower" ... Do you want me to add that again towards the end of the message? Commented Sep 3, 2019 at 10:35
  • couldnt hex be arranged in such a way that it forms common english letters?
    – Cryptic
    Commented Sep 4, 2019 at 1:30
  • No, I don't think so. Hex is just a way to express data, it always looks like that. Read more on hex here: lifewire.com/what-is-hexadecimal-2625897 Commented Sep 4, 2019 at 9:22
1

The data field is used especially when calling functions in contracts - all the data (called function name and arguments) go in that field.

So your contract can simply call a function in another contract with parameters - assuming the function accepts such parameters. So contracts take in extra data but calls to EOAs (Externally Owned Account) don't take extra data as they don't understand what to do with the data. I'm a bit unsure what happens to a transaction to an EOA with extra data - I guess it will just go through even if the receiver doesn't understand the data.

1

Send a message to a user.

It depends on what you mean by "send a message" and "to a user".

If you mean SMS, Email, push notification, etc., then no. This is because a fundamental limitation is that contracts can have only very limited interaction with the outside world.

  • Users sign transactions (input)
  • Functions can return values to other contracts (but not the outside world)
  • Functions can emit events.

You can create something similar to contracts sending messages to users based on listening to event logs, which are visible to everyone. Either the client app listens or an intermediary server listens, perchance to send an SMS, email or push notification.

Hope it helps.

2
  • By message I mean a message in hex that goes in the "data" field when you send transactions.
    – Cryptic
    Commented Sep 2, 2019 at 5:59
  • I am not sure but I have seen something about sending notifs via EPNS (Ethereum Push Notif Service)... Not exactly sure who it is for, but they seem to claim they can send notifs to wallets (and other things) via dApps/SmartContracts: prweb.com/releases/… Commented Feb 13, 2021 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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