Skip to main content

bytes

Pebble 0.3.1 · all symbols on this page are stable.

Raw byte string. Maps to Plutus Core ByteString. Used for hashes, policy IDs, token names, signatures, and anything else that's "just bytes on the wire".

Literals

FormExampleNotes
Hex literal#1a2b3cEach pair of hex digits is one byte. Case-insensitive.
Empty#""Zero-length byte string.
From string"MyToken".toBytes()UTF-8 encode a string literal.

Operators

CategoryOperators
Equality==, !=
Concatenation+
Ordering<, <=, >, >= (lexicographic)

Methods

MethodDescription
length(): intNumber of bytes.
slice(start: int, len: int): byteslen-byte sub-string starting at start. Clips on out-of-range.
prepend(byteVal: int): bytesReturns a new byte string with byteVal (0–255) prepended.
concat(other: bytes): bytesConcatenate; same as a + other.
indexAt(i: int): intByte at index i as 0–255. Fails on out-of-range.
equals(other: bytes): boolSame as ==.
lessThan(other: bytes): boolSame as <.
lessThanEquals(other: bytes): boolSame as <=.
greaterThan(other: bytes): boolSame as >.
greaterThanEquals(other: bytes): boolSame as >=.
toInt(): intParse as big-endian unsigned integer.

Examples (one per method)

const policy: bytes = #deadbeef;

const n: int = policy.length(); // 4
const sub: bytes = policy.slice(1, 2); // #adbe
const pre: bytes = policy.prepend(0xff); // #ffdeadbeef
const cat: bytes = #dead.concat(#beef); // #deadbeef
const at: int = policy.indexAt(0); // 222 (0xde)
const eq: bool = policy.equals(#deadbeef); // true
const lt: bool = #ab.lessThan(#cd); // true
const le: bool = #ab.lessThanEquals(#ab); // true
const gt: bool = #cd.greaterThan(#ab); // true
const ge: bool = #ab.greaterThanEquals(#ab); // true
const i: int = #04d2.toInt(); // 1234

Type aliases

The standard library defines several bytes aliases for clarity at usage sites:

AliasWidthUsed for
Hash2828Generic 224-bit hashes.
Hash3232Generic 256-bit hashes.
PubKeyHash28Blake2b-224 of a payment public key.
ScriptHash28Blake2b-224 of a serialized script.
TxHash32Blake2b-256 of a serialized transaction.
PolicyId28The script hash of a minting policy.
TokenName0–32An asset name within a policy.

These are aliases, not nominal types — you can freely pass a bytes where any of them is expected and vice versa.

See also

  • std.bytes — function-call surface
  • std.crypto — hash functions produce bytes
  • std.builtins — bitwise operations and consByteString, replicateByte, etc.