Skip to content
LogoLogo

channel.getStates

Gets TIP-20 channel reserve state for a channel ID, channel, or list of channels.

Usage

import { client } from './viem.config'
 
const state = await client.channel.getStates({
  channel:
    '0x0000000000000000000000000000000000000000000000000000000000000000',
})
 
console.log('Deposit:', state.deposit)
console.log('Settled:', state.settled)

Channel Input

Pass a channel when you want Viem to compute the channel ID before reading state.

import { client, channel } from './viem.config'
 
const state = await client.channel.getStates({
  channel,
})

Batch Input

Pass an array to fetch several channel states with one RPC call.

import { client } from './viem.config'
 
const states = await client.channel.getStates({
  channel: [
    '0x0000000000000000000000000000000000000000000000000000000000000000',
    '0x0000000000000000000000000000000000000000000000000000000000000001',
  ],
})
 
console.log(states[0]?.deposit)

Return Type

type ReturnType = {
  /** Unix timestamp when payer close was requested, or 0 if not requested */
  closeRequestedAt: number
  /** Total amount deposited in the channel */
  deposit: bigint
  /** Total amount settled to the payee */
  settled: bigint
}

When channel is an array, the return type is readonly ReturnType[].

Parameters

channel

  • Type: Hex | Channel.from.Value | readonly (Hex | Channel.from.Value)[]

Channel ID, channel, or list of channel 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.