Channel

await Channel.initialize({
url: 'ws://localhost:3001',
role: 'initiator'
initiatorId: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
responderId: 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',
initiatorAmount: 1e18,
responderAmount: 1e18,
pushAmount: 0,
channelReserve: 0,
ttl: 1000,
host: 'localhost',
port: 3002,
lockPeriod: 10,
async sign (tag, tx) => await account.signTransaction(tx)
})

Hierarchy (view full)

Constructors

Properties

_actionQueue: ChannelAction[] = []
_channelId?: `ch_${string}`
_eventEmitter: EventEmitter<DefaultEventMap> = ...
_fsmId?: `ba_${string}`
_isActionQueueLocked: boolean = false
_isMessageQueueLocked: boolean = false
_messageQueue: ChannelMessage[] = []
_nextRpcMessageId: number = 0
_options: ChannelOptions
_pingTimeoutId: Timeout
_rpcCallbacks: Map<number, ((message: object) => void)> = ...
_state: "" | `tx_${string}` = ''
_status: ChannelStatus = 'disconnected'
_websocket: w3cwebsocket

Methods

  • Get channel's fsm id

    Returns `ba_${string}`

  • Leave channel

    It is possible to leave a channel and then later reestablish the channel off-chain state and continue operation. When a leave method is called, the channel fsm passes it on to the peer fsm, reports the current mutually signed state and then terminates.

    The channel can be reestablished by instantiating another Channel instance with two extra params: existingChannelId and existingFsmId.

    Returns Promise<{
        channelId: `ch_${string}`;
        signedTx: `tx_${string}`;
    }>

    channel.leave().then(({ channelId, signedTx }) => {
    console.log(channelId)
    console.log(signedTx)
    })
  • Register event listener function

    Possible events:

    • "error"
    • "stateChanged"
    • "statusChanged"
    • "message"
    • "peerDisconnected"
    • "onChainTx"
    • "ownWithdrawLocked"
    • "withdrawLocked"
    • "ownDepositLocked"
    • "depositLocked"
    • "channelReestablished"
    • "newContract"

    Type Parameters

    Parameters

    Returns void

  • Get current round

    If round cannot be determined (for example when channel has not been opened) it will return null.

    Returns null | number

  • Trigger mutual close

    At any moment after the channel is opened, a closing procedure can be triggered. This can be done by either of the parties. The process is similar to the off-chain updates.

    Parameters

    • sign: SignTx

      Function which verifies and signs mutual close transaction

    Returns Promise<`tx_${string}`>

    channel.shutdown(
    async (tx) => await account.signTransaction(tx)
    ).then(tx => console.log('on_chain_tx', tx))
  • Get current state

    Returns Promise<{
        calls: EntUnpacked & {
            tag: CallsMtree;
        };
        halfSignedTx?: TxUnpacked & { tag: Tag.SignedTx; };
        signedTx?: TxUnpacked & { tag: Tag.SignedTx; };
        trees: EntUnpacked & {
            tag: StateTrees;
        };
    }>