Skip to content

createVoucher

Creates a notice output while processing an advance request.

Usage

The following example creates a voucher output of a ERC-20 transfer of 1 CTSI from the application to user 0x8f7599fa6fDDF2845a3beBcDCb055C7Ba1793a1f.

import { createApp } from "@deroll/app";
import { encodeFunctionData, erc20Abi, parseUnits } from "viem";
 
// create application
const app = createApp({ url: "http://127.0.0.1:5004" });
 
// log incoming advance request
app.addAdvanceHandler(async (data) => {
    const token = "0x491604c0FDF08347Dd1fa4Ee062a822A5DD06B5D"; // CTSI address
    const to = "0x8f7599fa6fDDF2845a3beBcDCb055C7Ba1793a1f"; // CTSI recipient
    const amount = parseUnits("1", 18); 
 
    const id = await app.createVoucher({ 
        destination: token, 
        payload: encodeFunctionData({ 
            abi: erc20Abi, 
            functionName: "transfer", 
            args: [to, amount], 
        }), 
    }); 
    return "accept";
});

Returns

Type: number

The id of the voucher output.

Parameters

destination

Type: Address

The address of the target smart contract of the voucher.

payload

Type: Hex

The ABI-encoded solidity call.