Contract Mastery: Built-in Functions

panic

Terminates the program unconditionally and reports a message which explains why the unrecoverable error occurred.

let optionalAccount: AuthAccount? = // ...

let account = optionalAccount ?? panic("missing account")

assert

Terminates the program if the given condition is false, and reports a message which explains how the condition is false. Use this function for internal sanity checks.

fun assert(_ condition: Bool, message: String)

RLP (Recursive Length Prefix)

RLP (Recursive Length Prefix) serialization allows the encoding of arbitrarily nested arrays of binary data. Cadence provides RLP decoding functions in the built-in RLP contract, which does not need to be imported.

fun decodeString(_ input: [UInt8]): [UInt8]

unsafeRandom

Returns a pseudo-random number.

This limitation is inherent to any smart contract platform that allows transactions to roll back atomically and cannot be solved through safe randomness alone. Providing additional Cadence language primitives to simplify this challenge for developers is on our roadmap as well.

fun unsafeRandom(): UInt64