0

In Ethereum transactions, you can use the Data field to send text. Here's an example testnet transaction.

https://ropsten.etherscan.io/tx/0x19e4921d572e7f513954c9dada66d7e4fb01d91b5c09be840b235c9fae73401e

If I understand correctly, the gas cost increases incrementally for each 256 bit hex word.

How many UTF-8 characters can you fit in each 256 bit hex word?

1
  • Some initial research - it seems like each 256 bit hex word can hold 64 hex characters, which would be equivalent to 32 UTF-8 chars. But this is pieced together from multiple sources so I am not confident yet
    – tjr226
    Commented May 5, 2021 at 19:22

2 Answers 2

0

UTF-8 characters have a minimum size of 1 byte, so assuming the smallest size per character, you can fit at most 32 characters (= 32 bytes = 256 bits). The size per character can go up to 4 bytes however, so it depends on what exactly you're trying to send.

If I understand correctly, the gas cost increases incrementally for each 256 bit hex word.

This only applies if you're using the Solidity ABI format for transaction data, since those values are encoded per 32 bytes. If you just send arbitrary bytes in a transaction, the data is not padded to form groups of 32 bytes. The gas cost for every 0-byte is 4 gas, and for every non-0-byte is 68 gas, so the total gas for a transaction (assuming there are no contracts involved) can be calculated as follows:

21,000 + (4 × <number of 0-bytes>) + (68 × <number of non-0-bytes>)
0

utf-8 is variable length. A character can take 1 byte (8 bits) up to 4 bytes (32 bits). This means that you can fit at least eight utf-8 characters in a 256 bit word.

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.