decodeOutput
Decodes a blob of output data as one of the functions of the rollups contracts Outputs interface: Notice, Voucher or DelegateCallVoucher.
Usage
import { } from "@cartesi/codec";
const = (
"0xc258d6e500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000",
);
// { type: "Notice", payload: "0xdeadbeef" }
switch (.) {
case "Notice":
.(.);
break;
case "Voucher":
.(., ., .);
break;
case "DelegateCallVoucher":
.(., .);
break;
}Parameters
data(Hex | Uint8Array): ABI-encoded output data, starting with the selector of one of theOutputsfunctions:Notice(0xc258d6e5),Voucher(0x237a816f) orDelegateCallVoucher(0x10321e8b).
Return Type
An Output union discriminated by the type field, with field names and types inferred from the Outputs ABI:
import type {
,
,
,
,
} from "@cartesi/codec";
// type Output = DelegateCallVoucher | Notice | Voucher;Notice — informational statement that can be validated on the base layer, but not executed:
type("Notice")payload(Hex | Uint8Array): application-specific payload of the notice.
Voucher — single-use permission to execute a CALL to a base layer contract on behalf of the application:
type("Voucher")destination(Address): address of the contract to be called.value(bigint): amount of Wei to be passed along the call.payload(Hex | Uint8Array): calldata of the call.
DelegateCallVoucher — single-use permission to execute a DELEGATECALL to a base layer contract in the context of the application contract:
type("DelegateCallVoucher")destination(Address): address of the contract to be delegate-called.payload(Hex | Uint8Array): calldata of the delegate call.
Addresses are returned checksummed.
Byte fields follow the representation of the encoded data: hex string in, hex string out; byte array in, byte array out. When decoding from a Uint8Array, the returned byte fields are zero-copy subarrays of the input — no data is copied.
Errors
Throws a viem AbiFunctionSignatureNotFoundError if the data does not start with the selector of one of the Outputs functions.