channel.open
Opens and funds a TIP-20 channel reserve channel.
Usage
import { parseUnits } from 'viem'
import { client } from './viem.config'
const { channelId, expiringNonceHash, receipt, salt } =
await client.channel.openSync({
deposit: parseUnits('100', 6),
payee: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
token: '0x20c0000000000000000000000000000000000001',
})
console.log('Channel:', channelId)
console.log('Expiring nonce hash:', expiringNonceHash)
console.log('Salt:', salt)
console.log('Transaction hash:', receipt.transactionHash)import { Account, createClient } from 'viem/tempo'
export const client = createClient({
account: Account.fromSecp256k1('0x...'),
})Deterministic Salt
By default, channel.open uses Hex.random(32) for salt. Pass an explicit salt when you need the channel ID to be deterministic for the same channel values.
import { parseUnits } from 'viem'
import { client } from './viem.config'
const { channelId } = await client.channel.openSync({
deposit: parseUnits('100', 6),
payee: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
salt:
'0x0000000000000000000000000000000000000000000000000000000000000000',
token: '0x20c0000000000000000000000000000000000001',
})Asynchronous Usage
The example above uses a *Sync variant of the action, that will wait for the transaction to be included before returning.
If you are optimizing for performance, you should use the non-sync channel.open action and wait for inclusion manually:
import { parseUnits } from 'viem'
import { Actions } from 'viem/tempo'
import { client } from './viem.config'
const hash = await client.channel.open({
deposit: parseUnits('100', 6),
payee: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
token: '0x20c0000000000000000000000000000000000001',
})
const receipt = await client.waitForTransactionReceipt({ hash })
const { args: { channelId } } =
Actions.channel.open.extractEvent(receipt.logs)Return Type
type ReturnType = {
/** Optional signer for vouchers */
authorizedSigner: Address
/** Channel ID */
channelId: Hex
/** Amount deposited in the channel */
deposit: bigint
/** Transaction-derived hash assigned when the channel was opened */
expiringNonceHash: Hex
/** Optional relayer allowed to submit settle for the payee */
operator: Address
/** Account that receives settled voucher payments */
payee: Address
/** Account that funded the channel and receives refunds */
payer: Address
/** Transaction receipt */
receipt: TransactionReceipt
/** User-supplied salt */
salt: Hex
/** TIP-20 token address held by the channel */
token: Address
}Parameters
authorizedSigner (optional)
- Type:
Address - Default:
zeroAddress
Optional signer for vouchers. When set to zero address, the payer signs vouchers.
deposit
- Type:
bigint
Amount of TIP-20 token to deposit.
operator (optional)
- Type:
Address - Default:
zeroAddress
Optional relayer allowed to submit settle for the payee.
payee
- Type:
Address
Account that receives settled voucher payments.
salt (optional)
- Type:
Hex - Default:
Hex.random(32)
User-supplied salt to distinguish otherwise identical channels.
token
- Type:
Address | bigint
TIP-20 token address or ID held by the channel.
account (optional)
- Type:
Account | Address
Account that will be used to send the transaction.
feeToken (optional)
- Type:
Address | bigint
Fee token for the transaction.
Can be an unpaused USD-denominated TIP-20 token address or ID. Use client.fee.validateToken({ token }) to validate a token before submitting a transaction or setting it as a fee preference.
feePayer (optional)
- Type:
Account | true
Fee payer for the transaction.
Can be a Viem Account, or true if a Fee Payer Service will be used.
gas (optional)
- Type:
bigint
Gas limit for the transaction.
maxFeePerGas (optional)
- Type:
bigint
Max fee per gas for the transaction.
maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas for the transaction.
nonce (optional)
- Type:
number
Nonce for the transaction.
nonceKey (optional)
- Type:
'expiring' | bigint
Nonce key for the transaction. Use 'expiring' to use expiring nonces (TIP-1009), which enables concurrent transaction submission without nonce ordering.
validBefore (optional)
- Type:
number
Unix timestamp before which the transaction must be included.
validAfter (optional)
- Type:
number
Unix timestamp after which the transaction can be included.
throwOnReceiptRevert (optional)
- Type:
boolean - Default:
true
Whether to throw an error if the transaction receipt indicates a revert. Only applicable to *Sync actions.