Skip to main content

Documentation Index

Fetch the complete documentation index at: https://compact-by-example.org/llms.txt

Use this file to discover all available pages before exploring further.

The Contract

pragma language_version 0.16;

import CompactStandardLibrary;

// On-chain storage for the message
export ledger message: Opaque<"string">;

// Store a new message
export circuit storeMessage(customMessage: Opaque<"string">): [] {
    disclose(message = customMessage);
}

// Retrieve the current message
export circuit getMessage(): Opaque<"string"> {
    return message;
}

How It Works

Pragma Directive

pragma language_version 0.16;
Specifies the compiler version.

Import Statement

import CompactStandardLibrary;
Provides essential types and functions.

Ledger Declaration

export ledger message: Opaque<"string">;
Declares on-chain state. Opaque<"string"> stores variable-length strings.

Circuits (Functions)

export circuit storeMessage(customMessage: Opaque<"string">): [] {
    disclose(message = customMessage);
}
Circuits are functions callable from external applications. [] means returns nothing.

The disclose() Function

disclose(message = customMessage);
Use disclose() when assigning user input to ledger variables to make data public.

What’s Next

First App - Counter

Build an interactive counter with validation

Primitive Types

Learn about Compact’s type system