Skip to main content

string

Pebble 0.3.1 · all symbols on this page are stable.

UTF-8 text. Maps to Plutus Core String. Primarily for logging via trace and for fail messages. Avoid storing large strings on-chain — every character costs CPU/memory in the script budget.

const msg: string = "Order filled";
trace(msg);

Literals

FormExampleNotes
Double-quoted"hello"UTF-8.
Empty""

Operators

CategoryOperators
Equality==, !=
Concatenation+

Methods

MethodDescription
toBytes(): bytesUTF-8 encode. Equivalent to std.builtins.encodeUtf8.

To go from bytes back to string, use std.builtins.decodeUtf8 (it fails on invalid UTF-8).

Examples

const greeting: string = "hello";
const u8: bytes = greeting.toBytes(); // #68656c6c6f

// Round-trip:
const back: string = std.builtins.decodeUtf8(u8); // "hello"

// Concatenation and equality:
const full: string = greeting + ", world";
assert full == "hello, world";

See also

  • std.builtinsappendString, equalsString, encodeUtf8, decodeUtf8
  • std.datastrToData / strFromData
  • Show — interface every type can implement to produce a string representation