# rollup.emitVoucher

Emits a **voucher** — a one-shot on-chain transaction authorized by the application: a destination, an ether value, and calldata. Once the epoch containing it settles, the voucher can be executed through the application contract, exactly once.

Encoded on-chain as `Voucher(address,uint256,bytes)` and added to the outputs merkle tree (provable).

## Usage

Plain value transfer:

```ts twoslash
import { Rollup } from '@deroll/cmio';
const rollup = new Rollup();
// ---cut---
const index = rollup.emitVoucher({
    destination: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    value: 1_000_000_000_000_000_000n, // 1 ETH in wei
});
```

Contract call (calldata in `payload`):

```ts twoslash
import { Rollup } from '@deroll/cmio';
const rollup = new Rollup();
declare const calldata: Uint8Array; // e.g. ERC-20 transfer(address,uint256)
// ---cut---
rollup.emitVoucher({
    destination: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
    payload: calldata,
});
```

## Returns

`number` — the output index: the voucher's position among all provable outputs ever emitted by the application. Off-chain components use it to fetch the voucher's proof for execution.

## Parameters

### destination

* Type: `AddressLike` — 0x-prefixed hex string, `Buffer` or `Uint8Array`
* Required; must be exactly 20 bytes

The address the voucher executes against: an EOA for transfers, a contract for calls.

### value

* Type: `U256Like` — `bigint`, `number`, or 32 bytes
* Default: `0n`

Amount of wei sent with the execution. Must fit in an unsigned 256-bit integer.

### payload

* Type: `BytesLike` — 0x-prefixed hex string, `Buffer` or `Uint8Array`
* Default: empty

EVM calldata to execute at `destination`. Leave empty for a plain transfer.

## Errors

| Condition | Error |
| --- | --- |
| `destination` not 20 bytes / malformed hex | `TypeError` |
| `value` negative or ≥ 2²⁵⁶ | `RangeError` |
| Voucher larger than the machine's output buffer | `RollupError` with negative `errno` |
