SLICE (binary data).
There are no usual “strings” (likewise, no floating-point numbers).
However, several techniques exist to store and return string-like data on-chain.
Embedding addresses as strings
Useaddress("...") to insert a constant standard address:
address, it has workchain and hash, but internally it’s a TVM SLICE, with 267 bits and 0 refs.
To return a human‑readable address, just address.
Client‑side libraries reconstruct and display addresses according to their own formatting rules.
Raw string literals
The syntaxval s = "abcd" is valid, but it does not produce a string; it produces a binary slice: each character is encoded with its char no.
Hex string literals
UsestringHexToSlice("...") to embed hexadecimal binary data:
Concatenating string literals
An example for"ab" and "cd". Because they are slices, concatenation is performed by via a builder:
How to return a string from a contract
A plainslice cannot be deserialized directly.
Like int — use int32 / coins / etc. to specify encoding.
Similarly, string‑like data must use an explicit encoding to be stored on‑chain.
Way #1: fixed-size strings via bitsN
If a response always contains 4 bytes of text, fixed‑size encodings may be used: bits32 or bytes4.
Way #2: “snake string”, or “tail string”
“Snake strings” (also called “tail strings”) are a standard encoding for arbitrary‑length strings, including those exceeding 127 characters. Snake encoding is: store portion of data → store rest in a ref cell. Here is a stringxxxxyyyyzzzz split into 3 parts:
"FFxxxx".ref(...). So “a tail” is because it goes after existing data up to the end.
MyTailString can be described in the simplest form as the remainder of a slice — RemainingBitsAndRefs (mentioned in an article about cells).
Way #3: variable-length encoding
Variable‑length encodings may also be implemented manually. For example, short strings like “abcd” can be stored like- 8 bits for N = string length
- N bits of data
Calculate hex / crc32 / etc. at compile-time
There are several functions operating on strings:stringCrc32("some_str")stringCrc16("some_str")stringSha256("some_crypto_key")stringSha256_32("some_crypto_key")stringToBase256("AB")