What is the maximum length of messages in a transaction?

The maximum number of characters you can send in a transaction depends on the method used and whether the message is plaintext or encrypted:

Method Type Max Length
Radix Wallet (v1.2) Plaintext 125
Radix Wallet (v1.2) Encrypted 64
Json-Rpc API Plaintext 125
Json-Rpc API Encrypted 64
Radix Wallet (v1.3) Plaintext 253
Radix Wallet (v1.3) Encrypted 192
Core API Plaintext 252*
Core API Encrypted 192

Explanation

Messages that are readable by the Radix Wallet and Explorer are first encoded using a simple scheme as follows:

Plaintext Message

Message: Hello

Key Bytes Value
Message Type 1 00
Encryption Scheme 1 00
Plaintext 5 48656c6c6f

The plaintext encoded message in bytes is therefore:
000048656c6c6f

Encrypted Message

Message: Hello

Key Bytes Value
Message Type 1 01
Encryption Scheme 1 ff
Ephemeral Public Key 33 03a0baf4510d589fa59c26f7f97d749f796424859b80716dc12a3b20a4e1ac9573
Nonce 12 0fd55101a52baab614b2f3e3
Auth Tag 16 8a2c1addb7d97abe5ecdcea02de4a670
Cipher Text 5 a399e28dee

The encrypted encoded message in bytes is therefore:
01ff03a0baf4510d589fa59c26f7f97d749f796424859b80716dc12a3b20a4e1ac95730fd55101a52baab614b2f3e38a2c1addb7d97abe5ecdcea02de4a670a399e28dee

Json-Rpc API / Radix Wallet (v1.2)

Convert the encoded message bytes into a string representation:

0x00 0x00 0x48 0x65 0x6c 0x6c 0x6f"000048656C6C6F"

Unfortunately, when this message string is submitted with transaction, the encoded message string is encoded again by converting each character into its hex string equivalent:

"000048656C6C6F""3030303034383635364336433646"0x33 0x30 0x33 0x30 0x33 0x30 0x33 0x30 0x33 0x34 0x33 0x38 0x33 0x36 0x33 0x35 0x33 0x36 0x34 0x33 0x33 0x36 0x34 0x33 0x33 0x36 0x34 0x36

So the message value that is actually stored in the message field on the ledger for this example grows from 7 bytes to 28 bytes.

The transaction message field has a maximum length of 255 bytes. After the double hex encoding we only have 127 bytes available for the message data (255/2 = 127.5 → 127 bytes):

  • For unencrypted messages we have a 2 byte header which leaves us with 125 bytes for the message content.
  • For encrypted messages we have a 63 bytes header which leaves us with 64 bytes for the message content.

Core API / Radix Wallet (v1.3)

Convert the encoded message bytes into a string representation:

0x00 0x00 0x48 0x65 0x6c 0x6c 0x6f"000048656C6C6F"

When the message string is submitted with the transaction, the string encoded message is converted back into bytes:

"000048656C6C6F"0x00 0x00 0x48 0x65 0x6c 0x6c 0x6f

The transaction field has a maximum length of 255 bytes:

  • For unencrypted messages we have a 2 byte header which leaves us with 253 bytes for the message content [*Where did the missing byte for Core API call go?]
  • For encrypted messages we have a 63 byte header which leaves us with 192 bytes for the message content.
6 Likes

Just wanted to say that the work you are doing is priceless. Thank you :slight_smile:

2 Likes

+1.
Helped me a lot.