Channel

Example

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

Constructors

Properties

_actionQueue: ChannelAction[] = []
_channelId?: `ch_${string}`
_eventEmitter: EventEmitter = ...
_fsmId?: `ba_${string}`
_isActionQueueLocked: boolean = false
_isMessageQueueLocked: boolean = false
_messageQueue: ChannelMessage[] = []
_nextRpcMessageId: number = 0
_options: ChannelOptions
_pingTimeoutId: Timeout
_rpcCallbacks: Map<number, ((message) => void)> = ...

Type declaration

    • (message): void
    • Parameters

      • message: object

      Returns 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 offchainTx (returned from leave method as channelId and signedTx respectively).

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

    Example

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

    Type Parameters

    Parameters

    • eventName: E

      Event name

    • callback: ChannelEvents[E]

      Callback function

    Returns void

  • Register event listener function

    Possible events:

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

    Type Parameters

    Parameters

    • eventName: E

      Event name

    • callback: ChannelEvents[E]

      Callback function

    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}`>

    Example

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

    Returns Promise<{
        calls: Object;
        halfSignedTx?: Object;
        signedTx?: Object;
        trees: Object;
    }>

Generated using TypeDoc