Skip to content
LogoLogo

Get Channel States

channel.getStates

Gets TIP-20 channel reserve state for a channel ID or channel.

Usage

import {  } from './viem.config'
 
const  = await ..({
  : '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
})
 
.('Channel state:', )
Channel state: { closeRequestedAt: 0, deposit: 100000000n, settled: 40000000n }

Recipes

Audit Capacity Across Many Channels

Pass a list of channel IDs to read every state in one call, then compare deposits against settled amounts to find channels that need a top-up.

import {  } from './viem.config'
 
const  = await ..({
  : [
    '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
    '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
  ],
})
 
const  = .(() => . - .)
 
.('Remaining capacity:', )
Remaining capacity: [60000000n, 25000000n]

Alert the Payee When a Close Is Requested

Poll closeRequestedAt to detect a payer's close request; a non-zero value starts the window to settle the final voucher with channel.settle.

import {  } from 'viem/tempo'
import {  } from './viem.config'
 
const  = await ..({
  : '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
})
 
if (. > 0) {
  const  = (.) + .
  .('Settle vouchers before:', new (() * 1000))
}

Return Value

type ReturnType = {
  settled: bigint
  deposit: bigint
  closeRequestedAt: number
}

A single channel state for a single channel input, or a readonly list of channel states for a channel list.

Parameters

channel

  • Type: Hex | Channel | readonly (Hex | Channel)[]

Channel ID, channel, or list of IDs and channels.

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.