Skip to main content

Types

Pebble supports a few built-in types.

Each of these builtin types maps directly a corresponding UPLC type under the hood.

Primitives

Pebble provides four primitive types that map directly to Plutus Core:

  • int
  • bool
  • bytes
  • string

These types form the foundation for all Pebble contracts.

int

Arbitrary-precision signed integer.
Backed by Plutus Integer.

Example

const supply: int = 1_000_000;
let spent: int = 500;

assert (supply - spent) >= 0;

Operators

  • Arithmetic: +, -, *, /, %
  • Comparison: <, <=, >, >=, ==, !=

bytes

Raw byte arrays. Commonly used for hashes, policy IDs, token names, and low-level identifiers.

Example

const policy: bytes = #deadbeef;
const token: bytes = "MyToken".toBytes();

assert tx.outputs[0].value.amountOf(policy, token) > 0;

Pebble represents token names as bytes const token: bytes = "MyToken".toBytes(). This ensures compatibility with Plutus, where token names are byte arrays.

Common Operators

  • Equality: ==, !=
  • Concatenation: a + b
  • Conversion: "hello".toBytes()
  • Hashing: hash(bytesVal)

string

UTF-8 encoded text. Primarily for logging and off-chain metadata. Avoid storing large strings on-chain due to cost.

Example

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

bool

Logical true/false values. Derived from comparisons or logical expressions.

Example

const signed: bool = tx.signatories.includes(ownerHash);

if (signed && tx.outputs.length() > 0) {
trace("Valid transaction");
} else {
fail "Unauthorized";
}

Operators

  • Logical: &&, ||, !
  • Comparisons return bool

Cardano-Specific

See Types for all cardano-specific types supported in Pebble.

Refer stdScope.ts for details regarding their definition.

Optional / Sum Types

Option<T>

Use Option<T> to represent values that may or may not exist.

Example

const maybeDatum: Option<int> = Some{ value: 10 };

case/match used for destructuring

match maybeDatum {
Some{ value }: trace(value),
None{} : fail "missing datum"
}

Destructuring -

const InlineDatum{ datum: { owner, token, minAmount } as Order } = spendingInput.datum;

Structs

Defined using struct declarations.

struct defines custom composite type with named fields.

struct Order {
ownerPaymentCreds: Credential,
policy: bytes,
tokenName: bytes,
minReceiveAmount: int
}