Skip to content

Vouchers

Vouchers are outputs produced by Cartesi applications that allows the execution of code on the base layer of the rollup. Vouchers can encapsulate any arbitrary smart contract call, and can be executed by anyone by calling the executeVoucher method of the application smart contract.

One essential piece of information to execute a voucher, as required by the executeVoucher method, is the voucher proof. Proofs are generated by a Cartesi node every time an epoch closes. Epochs are configurable, and are tipically closed once a week.

Creating a voucher is easy by using the encodeFunctionData viem function. The following example creates a voucher to make a transfer of an ERC-20 token.

import { Voucher } from "@deroll/core";
import { encodeFunctionData, erc20Abi, parseUnits } from "viem";
 
const token = "0x491604c0FDF08347Dd1fa4Ee062a822A5DD06B5D"; // CTSI address
const to = "0x8f7599fa6fDDF2845a3beBcDCb055C7Ba1793a1f"; // CTSI recipient
const amount = parseUnits("1", 18);
const voucher: Voucher = {
    destination: token,
    payload: encodeFunctionData({
        abi: erc20Abi,
        functionName: "transfer",
        args: [to, amount],
    }),
};