# createDelegateCallVoucher

Creates a delegate-call voucher output while processing an advance request.

A delegate-call voucher is like a [voucher](/app/create-voucher), but the application contract executes the `destination` code with `DELEGATECALL` instead of `CALL`. The destination's code therefore runs in the application contract's own context (its storage, balance, and address), as opposed to a regular voucher, which calls out to another contract. This is useful for executing library or batch-executor logic *as* the application, for example performing several actions atomically in a single output.

:::info
Because the call runs in the application's own context, a delegate-call voucher cannot transfer Ether and has no `value` field — only `destination` and `payload`.
:::

## Usage

The following example creates a delegate-call voucher that performs two ERC-20 transfers atomically, by delegate-calling a deployed batch-executor contract whose `executeBatch` code runs in the application contract's context.

```ts twoslash
import { createApp } from "@deroll/app";
import { encodeFunctionData, erc20Abi, parseAbi, parseUnits } from "viem";

// create application
const app = createApp();

// log incoming advance request
app.addAdvanceHandler(async (data) => {
    const executor = "0xcA11bde05977b3631167028862bE2a173976CA11"; // batch-executor address // [!code focus]
    const token = "0x491604c0FDF08347Dd1fa4Ee062a822A5DD06B5D"; // CTSI address
    const alice = "0x8f7599fa6fDDF2845a3beBcDCb055C7Ba1793a1f";
    const bob = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";

    const id = await app.createDelegateCallVoucher({ // [!code focus]
        destination: executor, // [!code focus]
        payload: encodeFunctionData({ // [!code focus]
            abi: parseAbi([ // [!code focus]
                "function executeBatch(address[] targets, bytes[] payloads)", // [!code focus]
            ]), // [!code focus]
            functionName: "executeBatch", // [!code focus]
            args: [ // [!code focus]
                [token, token], // [!code focus]
                [ // [!code focus]
                    encodeFunctionData({ // [!code focus]
                        abi: erc20Abi, // [!code focus]
                        functionName: "transfer", // [!code focus]
                        args: [alice, parseUnits("1", 18)], // [!code focus]
                    }), // [!code focus]
                    encodeFunctionData({ // [!code focus]
                        abi: erc20Abi, // [!code focus]
                        functionName: "transfer", // [!code focus]
                        args: [bob, parseUnits("2", 18)], // [!code focus]
                    }), // [!code focus]
                ], // [!code focus]
            ], // [!code focus]
        }), // [!code focus]
    }); // [!code focus]
    return "accept";
});
```

## Returns

Type: `number`

The id of the delegate-call voucher output.

## Parameters

### destination

Type: `Address`

The address of the contract whose code is executed in the application contract's context.

### payload

Type: `Hex`

The ABI-encoded solidity call.
