Skip to content
Logo

Types & Constants

Everything the package exports besides the Rollup class (the RollupError class is documented under Errors). All types are importable with import type:

import type {
    ,
    AdvanceRequest,
    ,
    ,
    DelegateCallVoucher,
    GioResponse,
    ,
    InspectRequest,
    ,
    ,
    ,
    ,
    RunHandlers,
    ,
    Voucher,
} from "@cartesi/rollup";

Input types

Three "like" types describe what the binding accepts and converts automatically — see byte and number conventions. Hex strings are Hex (`0x${string}`), structurally identical to viem's Hex/Address:

TypeAcceptsUsed for
BytesLikeHex, Buffer, Uint8Arraypayloads, gio ids
AddressLikeHex, Buffer, Uint8Array (20 bytes)voucher destinations
U256Likebigint, number, Hex, Uint8Array (32 bytes)voucher values

Output argument types

The two voucher emitters take a named options object, importable for typing helpers that build outputs:

  • Voucher — argument of emitVoucher: destination (AddressLike), optional value (U256Like, default 0n) and payload (BytesLike, default empty).
  • DelegateCallVoucher — argument of emitDelegateCallVoucher: destination (AddressLike) and optional payload (BytesLike). No valueDELEGATECALL cannot transfer ether.
import type { Voucher, DelegateCallVoucher } from "@cartesi/rollup";
 
const : Voucher = {
    : "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
    : 1_000_000_000_000_000_000n,
};
 
const : DelegateCallVoucher = {
    : "0x5FbDB2315678afecb367f032d93F642f64180aa3",
};

Request types

finish returns RollupRequest, the discriminated union of:

  • AdvanceRequesttype: "advance" plus the input metadata (chainId, appContract, msgSender, blockNumber, blockTimestamp, prevRandao, index) and payload.
  • InspectRequesttype: "inspect" and payload.
const  = .();
if (. === "advance") {
    .indexArrow

Input index relative to all inputs ever sent to the application.

;
}

Handler types

RunHandlers is the parameter of run — an optional advance and inspect handler, each receiving (request, rollup) and returning boolean | void, possibly wrapped in a Promise.

RequestHandler<request> is the handler chain and broadcast compose: the same (request, rollup), but returning boolean | Promise<boolean> — inside a composition, a missing answer has no sensible meaning (why). AdvanceRequestHandler and InspectRequestHandler are it, specialized to one request kind:

import type { ,  } from "@cartesi/rollup";
 
const :  = (, ) => {
    .(.);
    return true;
};
 
const :  = (, ) => {
    .(.);
    return true;
};

boolean is assignable to boolean | void, so either of them — composed or not — can be passed to run directly.

Response types

GioResponse is returned by gio: { responseCode: number, responseData: Buffer }.

Constants

import { ,  } from "@cartesi/rollup";
 
ADDRESS_LENGTHArrow

Length of an EVM address, in bytes.

;
U256_LENGTHArrow

Length of an EVM word, in bytes.

;

driver (typed RollupDriver) reports which libcmt IO driver the native addon was built against — "ioctl" for the real Cartesi Machine kernel driver on riscv64, "mock" for the file-based host simulation. The choice is made at build time from the target architecture, so it is the honest answer to "am I running inside a machine?", where CMT_INPUTS being set is only a hint:

import {  } from "@cartesi/rollup";
 
driverArrow

The libcmt IO driver this addon was built against: "ioctl" for the real Cartesi Machine driver (riscv64), "mock" for the file-based simulation used on development hosts.

It is decided by binding.gyp from the target architecture, at build time — not by the environment, so it is the truth about which half of libcmt is running, where CMT_INPUTS being set is only a hint.

;

Errors

Failed libcmt calls throw a RollupError (a subclass of Error) with two extra properties:

PropertyTypeMeaning
errnonumberThe negative errno from libcmt (e.g. -16 for EBUSY)
syscallstringThe libcmt call that failed (e.g. cmt_rollup_init)

RollupError is exported as a value, so it can be caught with instanceof:

import { ,  } from "@cartesi/rollup";
 
try {
    new ();
} catch () {
    if ( instanceof ) {
        .errnoArrow

Negative errno reported by libcmt (e.g. -16 for EBUSY).

;
} }

Argument validation failures throw plain TypeError / RangeError before reaching the device.