channel.verifyVoucher
Verifies a TIP-20 channel reserve voucher signature.
Returns whether signature is a valid voucher for cumulativeAmount from the channel's voucher signer: its authorizedSigner when set, else the payer. It does not check cumulativeAmount against the channel's deposit or settled amount, so a valid voucher can still fail to settle. Use channel.getStates to read the deposit and settled amount.
Usage
import { parseUnits } from 'viem'
import { client, channel } from './viem.config'
const valid = await client.channel.verifyVoucher({
channel,
cumulativeAmount: parseUnits('40', 6),
signature: '0x...',
})
trueimport { Account, createClient } from 'viem/tempo'
export const client = createClient({
account: Account.fromSecp256k1('0x...'),
})
import { Channel } from 'viem/tempo'
export const channel = Channel.from({
expiringNonceHash:
'0x0000000000000000000000000000000000000000000000000000000000000000',
payee: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
payer: client.account.address,
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
token: '0x20c0000000000000000000000000000000000001',
})Standalone Action
import { parseUnits } from 'viem'
import { Actions } from 'viem/tempo'
import { client, channel } from './viem.config'
const valid = await Actions.channel.verifyVoucher(client, {
channel,
cumulativeAmount: parseUnits('40', 6),
signature: '0x...',
})
trueReturn Value
boolean
Whether the signature is a valid voucher for the channel and amount.
Parameters
channel
- Type:
Channel.from.Value
Channel descriptor. The precompile computes the channel ID from it, so a channel ID alone is not enough.
const channel = Channel.from({
expiringNonceHash: '0x...',
payee: '0x...',
payer: client.account.address,
salt: '0x...',
token: '0x...',
})
await client.channel.verifyVoucher({
channel,
cumulativeAmount: parseUnits('40', 6),
signature: '0x...',
})cumulativeAmount
- Type:
bigint
Total voucher amount signed for the channel.
await client.channel.verifyVoucher({
channel,
cumulativeAmount: parseUnits('40', 6),
signature: '0x...',
})signature
- Type:
Hex
Voucher signature, from channel.signVoucher.
await client.channel.verifyVoucher({
channel,
cumulativeAmount: parseUnits('40', 6),
signature: '0x...',
})blockNumber (optional)
- Type:
bigint
Block number to read the state from.
blockOverrides (optional)
- Type:
BlockOverrides
Block overrides to apply to the state.
blockTag (optional)
- Type:
BlockTag
Block tag to read the state from.
stateOverride (optional)
- Type:
StateOverride
State override to apply.
Errors
| Error | Description |
|---|---|
ChannelNotFoundError | The channel does not exist. |