Parameters and Return Values

Parameters

Circuits can take typed parameters. The return type is written after :, and use [] for “no value”.

Source: Circuits

export circuit transfer(to: Bytes<32>, amount: Uint<64>): [] {
    // use 'to' and 'amount'
}

Multiple Parameters

export circuit multiParam(
    a: Uint<64>,
    b: Uint<64>,
    flag: Boolean
): [] {
    // ...
}

Parameter Types

Parameters can be any Compact type:

  • Primitives: Boolean, Field, Uint<N>, Bytes<N>
  • Compounds: [T, U] (tuples), Vector<N, T>
  • User-defined: structs, enums
  • Standard library types: Maybe<T>, Either<A, B> (requires import CompactStandardLibrary)

Source: Primitive types, User-defined types

Return Values

Single Return

export circuit getBalance(): Uint<64> {
    return 100;  // Returns a Uint<64>
}

No Return (Empty Tuple)

export ledger counter: Counter;

export circuit performAction(): [] {
    // Do something, return nothing
    counter.increment(1);
}

Example storing a message with no return value:

export ledger message: Opaque<"string">;

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

Source: Hello world

Tuple Return

Return multiple values using tuples:

export circuit getStats(): [Uint<64>, Boolean] {
    return [100, true];
}

Struct Return

export struct Result {
    value: Uint<64>,
    success: Boolean
}

export circuit compute(): Result {
    return Result {
        value: 42,
        success: true
    };
}

Using Return Values

From other circuits:

export ledger counter: Counter;

circuit calculate(): Uint<16> {
    return 100;
}

export circuit useCalculation(): [] {
    const result = calculate();
    counter.increment(result);  // Counter.increment expects Uint<16>
}

Source: Circuit and witness calls

From TypeScript (after deployment):

Exported circuits are accessible via the generated Contract class, which exposes circuits and impureCircuits properties. The exact call pattern depends on your SDK version, but return types map to their TypeScript equivalents.

Source: TypeScript target, Representations in TypeScript

Exercises

Complete exercises/03_circuits/02_parameters/ and exercises/03_circuits/03_return_values/.