State channel WebSocket API
Messages on the WebSocket API have to follow JSON-RPC specification version 2.0. See: www.jsonrpc.org
The WebSocket API provides the following actions:
Update
Roles:
Sender
Acknowledger
Sender trigger an update
method:
channels.update.new
params:
from
string
Participant's account to take coins from
Yes
to
string
Participant's account to add coins to
Yes
amount
integer
Amount of coins to transfer
Yes
block_hash
string
The on-chain block hash to pin the off-chain environment
No
meta
array of strings
Meta information about the update
No
Example
Sender receives a non-authenticated off-chain state
method:
channels.sign.update
params:
signed_tx
string
channel_offchain_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
off-chain updates
Yes
Example
Sender authenticates off-chain state response
method:
channels.update
params:
signed_tx
string
solo-authenticated channel_offchain_tx
transaction
Yes
Example
Acknowledger receives a non-authenticated off-chain state
method:
channels.sign.update_ack
params:
signed_tx
string
solo-authenticated channel_offchain_tx
transaction
Yes
updates
list
off-chain updates
Yes
Example
Acknowledger authenticated off-chain state response
method:
channels.update_ack
params:
signed_tx
string
co-authenticated channel_offchain_tx
transaction
Yes
Example
Update conflict
method:
channels.conflict
params:
channel_id
string
channel id
Yes
data
object
description of the last mutually authenticated state
Yes
data:
channel_id
string
channel id
Yes
round
object
the round of the last mutually authenticated state
Yes
Example
Update error
error:
message
string
error message
Yes
code
integer
error code
Yes
data
json
error description
Yes
request
json
the failed request
Yes
data:
message
string
JSON-RPC error message
Yes
code
integer
JSON-RPC error code
Yes
Example
Deposit
Roles:
Depositor
Acknowledger
Depositor trigger a update
method:
channels.deposit
params:
amount
integer
Amount of coins to deposit in the channel
Yes
block_hash
string
The on-chain block hash to pin the off-chain environment
No
fee
integer
The on-chain transaction fee to be used. If not provided the FSM picks a value for the client
No
gas_price
integer
the gas_price to be used for the fee computation
No
nonce
integer
the nonce to be used in the transaction
No
meta
array of strings
Meta information about the update
No
Example
Depositor receives an non-authenticated deposit transaction
method:
channels.sign.deposit_tx
params:
channel_id
string
channel ID
Yes
data
object
deposit data
Yes
data:
signed_tx
string
channel_deposit_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
off-chain updates
Yes
Example
Depositor authenticates deposit response
method:
channels.deposit_tx
params:
signed_tx
string
solo-authenticated channel_deposit_tx
transaction
Yes
Example
Acknowledger receives a non-authenticated deposit transaction
method:
channels.sign.deposit_ack
params:
channel_id
string
channel ID
Yes
data
object
deposit data
Yes
data:
signed_tx
string
solo-authenticated channel_deposit_tx
transaction
Yes
updates
list
off-chain updates
Yes
Example
Acknowledger authenticates deposit response
method:
channels.deposit_ack
params:
signed_tx
string
co-authenticated channel_deposit_tx
transaction
Yes
Example
Withdrawal
Roles:
Withdrawer
Acknowledger
Withdrawer trigger a update
method:
channels.withdraw
params:
amount
integer
Amount of coins to withdraw form the channel
Yes
block_hash
string
The on-chain block hash to pin the off-chain environment
No
fee
integer
The on-chain transaction fee to be used. If not provided the FSM picks a value for the client
No
gas_price
integer
the gas_price to be used for the fee computation
No
nonce
integer
the nonce to be used in the transaction
No
meta
array of strings
Meta information about the update
No
Example
Withdrawer receives a non-authenticated withdraw transaction
method:
channels.sign.withdraw_tx
payload:
channel_id
string
channel ID
Yes
data
object
withdrawal data
Yes
data:
signed_tx
string
channel_withdraw_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
off-chain updates
Yes
Example
Withdrawer authenticates withdraw response
method:
channels.withdraw_tx
params:
signed_tx
string
co-authenticated channel_withdraw_tx
transaction
Yes
Example
Acknowledger receives a non-authenticated withdraw transaction
method:
channels.sign.withdraw_ack
params:
channel_id
string
channel ID
Yes
data
object
withdrawal data
Yes
data:
signed_tx
string
solo-authenticated channel_withdraw_tx
transaction
Yes
updates
list
off-chain updates
Yes
Example
Acknowledger authenticates withdraw response
method:
channels.withdraw_ack
params:
signed_tx
string
co-authenticated channel_withdraw_tx
transaction
Yes
Example
Assume Minimum Depth
method:
channels.assume_minimum_depth
params:
tx_hash
string
The on-chain hash of related transaction
yes
Example
Contracts
Contract create
method:
channels.update.new_contract
params:
code
contract code
contract code
Yes
call_data
call data
call data for contract creation
Yes
vm_version
integer
contract virtual machine version (vm for which code was compiled)
Yes
abi_version
integer
contract virtual machine abi version
Yes
deposit
integer
contract creation deposit
Yes
block_hash
string
The on-chain block hash to pin the off-chain environment
No
meta
array of strings
Meta information about the update
No
Example
Contract call
method:
channels.update.call_contract
params:
contract_id
contract id
contract to call
Yes
call_data
call data
call data
Yes
abi_version
integer
call abi version
Yes
amount
integer
amount of coins to transfer to contract
Yes
block_hash
string
The on-chain block hash to pin the off-chain environment
No
meta
array of strings
Meta information about the update
No
Example
Generic message
Roles:
Sender
Receiver
Sender send message
method:
channels.message
params:
to
string
Receiver's address
Yes
info
string
Message body
Yes
Example
Receiver receives message
method:
channels.message
params:
channel_id
string
channel id
Yes
data
object
data field that contains the message
Yes
data:
message
object
the message itself
Yes
message:
channel_id
string
channel id
Yes
from
string
Sender's address
Yes
to
string
Receiver's address
Yes
info
string
Message body
Yes
Example
Close mutual
Roles:
Closer
Acknowledger
Closer initiate mutual close
method:
channels.shutdown
params:
block_hash
string
The on-chain block hash to pin the off-chain environment
No
fee
integer
The on-chain transaction fee to be used. If not provided the FSM picks a value for the client
No
gas_price
integer
the gas_price to be used for the fee computation
No
nonce
integer
the nonce to be used in the transaction
No
Example
Closer receives mutual close
method:
channels.sign.shutdown_sign
params:
channel_id
string
channel ID
Yes
data
object
closing data
Yes
data:
signed_tx
string
channel_close_mutual_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
off-chain updates
Yes
Example
Closer returns an authenticated mutual close
method:
channels.shutdown_sign
params:
signed_tx
string
solo-authenticated channel_close_mutual_tx
transaction
Yes
Example
Acknowledger receives mutual close
method:
channels.sign.shutdown_sign_ack
params:
channel_id
string
channel ID
Yes
data
object
closing data
Yes
data:
signed_tx
string
solo-authenticated channel_close_mutual_tx
transaction
Yes
updates
list
off-chain updates
Yes
Example
Acknowledger returns an authenticated mutual close
method:
channels.shutdown_sign_ack
params:
signed_tx
string
co-authenticated channel_close_mutual_tx
transaction
Yes
Example
Snapshot
Roles:
Snapshotter
Snapshotter is prompted to snapshot (not mandatory step)
method:
channels.on_chain_tx
params:
info
string
"can_snapshot"
Yes
tx
string
the last on-chain transaction that could be disputed by a snapshot
Yes
Example
Snapshotter initiates solo snapshot
method:
channels.snapshot_solo
params:
fee
integer
The on-chain transaction fee to be used. If not provided the FSM picks a value for the client
No
gas_price
integer
the gas_price to be used for the fee computation
No
nonce
integer
the nonce to be used in the transaction
No
Example
Snapshotter receives solo snapshot
method:
channels.sign.snapshot_solo_tx
params:
channel_id
string
channel ID
Yes
data
object
closing data
Yes
data:
signed_tx
string
channel_snapshot_solo_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
empty list
Yes
Example
Snapshotter returns an authenticated solo snapshot
method:
channels.snapshot_solo_sign
params:
signed_tx
string
solo-authenticated channel_snapshot_solo_tx
transaction
Yes
Example
Force progress
Roles:
Forcer
Forcer initiates a force progress
method:
channels.force_progress
params:
contract_id
contract id
contract to call
Yes
call_data
call data
call data
Yes
abi_version
integer
call abi version
Yes
amount
integer
amount of coins to transfer to contract
Yes
gas_price
integer
the gas_price to be used for the fee computation and the update execution
Yes
gas
integer
gas limit, if not provided 1000000
is the default value
No
nonce
integer
the nonce to be used in the transaction
No
Example
Forcer receives a prepared force progress transaction to authenticate
method:
channels.sign.force_progress_tx
params:
channel_id
string
channel ID
Yes
data
object
closing data
Yes
data:
signed_tx
string
channel_force_progress_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
a list of a single update
Yes
update
amount
integer
the coins amount given to the off-chain contract
Yes
abi_version
integer
abi version
Yes
call_data
integer
contract execution call data
Yes
call_stack
list
contract execution call stack
Yes
caller_id
string
ID of the caller
Yes
contract_id
string
contract ID to be executed
Yes
gas
integer
gas limit
Yes
gas_price
integer
gas price
Yes
op
string
"OffChainCallContract"
Yes
Example
Forcer returns an authenticated force progress transaction
method:
channels.force_progress_sign
params:
signed_tx
string
solo-authenticated channel_snapshot_solo_tx
transaction
Yes
Example
Contract dry run
method:
channels.dry_run.call_contract
params:
contract_id
contract id
contract to call
Yes
call_data
call data
call data
Yes
abi_version
integer
call abi version
Yes
amount
integer
amount of coins to transfer to contract
Yes
block_hash
string
The on-chain block hash to pin the off-chain environment
No
meta
array of strings
Meta information about the update
No
Example
On-chain transactions
method:
channels.on_chain_tx
params:
channel_id
string
channel ID
Yes
data
object
closing data
Yes
data:
info
string
specific type of event
Yes
signed_tx
string
a mutually authenticated transaction that is posted on-chain
Yes
type
transaction type
Yes
The info
values could be:
"funding_signed"
- reported by theinitiator
, indicating that achannel_create_tx
has been singly authenticated by theinitiator
client, and sent to theresponder
for co-signing."funding_created"
- reported by theresponder
, indicating that achannel_create_tx
has been co-authenticated, and will be pushed to the mempool."deposit_signed"
- reported by thedepositor
, indicating that achannel_deposit_tx
has been singly authenticated by thedepositor
client, and sent to theacknowledger
for co-signing."deposit_created"
- reported by theacknowledger
, indicating that achannel_deposit_tx
has been co-authenticated, and will be pushed to the mempool."withdraw_signed"
- reported by thewithdrawer
, indicating that achannel_withdraw_tx
has been singly authenticated by thewithdrawer
client, and sent to theacknowledger
for co-signing."withdraw_created"
- reported by theacknowledger
, indicating that achannel_withdraw_tx
has been co-authenticated, and will be pushed to the mempool."channel_changed"
- reported by both parties, indicating that the fsm has detected a channel-related transaction on-chain. Note that this will be reported also for thechannel_create_tx
, once it appears on-chain. This means that each client will get twoon_chain_tx
reports for the create, deposit, withdraw and close_mutual transactions."close_mutual"
- reported by both parties, indicating that achannel_close_mutual_tx
has been co-authenticated, and will be pushed to the mempool."channel_closed"
- reported by both parties, when the on-chain channel state is detected to transition to aclosed
state."solo_closing"
- reported by both parties, when the on-chain channel state is detected to transition to a propersolo_closing
state - that is, with the latest known state."can_slash"
or"can_snapshot"
- reported by both parties, when the on-chain channel state is seen to transition into an improper state - that is, when there exists a later mutually authenticated state than the one reported by either party on-chain. If the channel is not yet closing - that could be a maliciouschannel_force_progress_tx
and the reportedinfo
value is"can_snapshot"
. If the malicious on-chain transaction ischannel_close_solo_tx
or the channel is already closing and achannel_force_progress_tx
is received - then theinfo
is"can_slash"
. Other transactions with an olderround
than the latest off-chain are not considered harmful.
Example
Close solo
Roles:
Closer
Closer initiated solo close
method:
channels.close_solo
params:
fee
integer
The on-chain transaction fee to be used. If not provided the FSM picks a value for the client
No
gas_price
integer
the gas_price to be used for the fee computation
No
nonce
integer
the nonce to be used in the transaction
No
Example
Closer receives solo close
method:
channels.sign.close_solo_sign
params:
channel_id
string
channel ID
Yes
data
object
closing data
Yes
data:
signed_tx
string
channel_close_solo_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
off-chain updates
Yes
Example
Closer returns an authenticated solo close
method:
channels.close_solo_sign
params:
signed_tx
string
solo-authenticated channel_close_solo_tx
transaction
Yes
Example
Slash
Roles:
Slasher
Slasher initiated slash
method: `channels.slash
params:
fee
integer
The on-chain transaction fee to be used. If not provided the FSM picks a value for the client
No
gas_price
integer
the gas_price to be used for the fee computation
No
nonce
integer
the nonce to be used in the transaction
No
Example
Slasher receives slash
method:
channels.sign.slash_tx
params:
channel_id
string
channel ID
Yes
data
object
closing data
Yes
data:
signed_tx
string
channel_slash_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
off-chain updates
Yes
Example
Slasher returns an authenticated slash
method: `channels.slash_sign
params:
signed_tx
string
solo-authenticated channel_slash_tx
transaction
Yes
Example
Slash
Roles:
Slasher
Slasher is prompted to slash
method:
channels.on_chain_tx
params:
info
string
"can_slash"
Yes
tx
string
the last on-chain transaction that could be slashed
Yes
Example
Slasher initiates slash
method:
channels.slash
Example
Slasher receives slash
method:
channels.sign.slash
params:
channel_id
string
channel ID
Yes
data
object
slashing data
Yes
data:
signed_tx
string
channel_slash
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
empty list of updates updates
Yes
Example
Slasher returns an authenticated slash
method:
channels.slash_sign
params:
signed_tx
string
solo-authenticated channel_slash
transaction
Yes
Example
Settle
Roles:
Settler
Settler initiates settle
method:
channels.settle
params:
fee
integer
The on-chain transaction fee to be used. If not provided the FSM picks a value for the client
No
gas_price
integer
the gas_price to be used for the fee computation
No
nonce
integer
the nonce to be used in the transaction
No
Example
Settler receives settle
method:
channels.sign.settle_sign
params:
channel_id
string
channel ID
Yes
data
object
settle data
Yes
data:
signed_tx
string
channel_settle_tx
transaction wrapped in a signed_tx
with no authentication
Yes
updates
list
off-chain updates
Yes
Example
Settler returns an authenticated settle
method:
channels.settle_sign
params:
signed_tx
string
solo-authenticated channel_settle_tx
transaction
Yes
Example
Leave
Roles:
Leaver
Acknowledger
Leaver initiates leave
method:
channels.leave
Example
Leaver and Acknowledger inform their clients
method:
channels.leave
params:
channel_id
string
channel ID
Yes
data
object
closing data
Yes
data:
state
string
a mutually authenticated last state transaction
Yes
Example
Info messages
Info
method:
channels.info
params:
channel_id
string
channel ID
Yes
data
object
info data
Yes
data:
event
string
event description
Yes
Example
Latest state
method:
channels.get.offchain_state
Response
result:
trees
channel state trees
calls
channel call state tree
half_signed_tx
channel latest half authenticated tx or ''
if equal to latest authenticated tx
signed_tx
channel latest mutually authenticated tx or ''
if not available
Example
Request
Response
Latest contract state
method:
channels.get.contract
params:
pubkey
string
requested contract pubkey
Yes
Response
result:
contract
object with contract details
contract->id
contract id (equals to the requested pubkey)
contract->owner_id
contract owner id
contract->vm_version
contract vm version (integer)
contract->abi_version
contract ABI version (integer)
contract->active
"is contract active?" boolean
contract->referrer_ids
referrer ids list
contract->deposit
contract deposit
contract_state
object with contract state
Example
Request
Response
System messages
ping
method:
channels.system
params:
action
string
the value "ping"
Yes
Response
method:
channels.system
params.data:
action
"system"
tag
"pong"
Example
Request
Response
Signing Error Replies
method:
channels.initiator_sign | channels.responder_sign | channels.deposit_tx | channels.deposit_ack | channels.withdraw_tx | channels.withdraw_ack | channels.responder_sign | channels.snapshot_solo_tx | channels.snapshot_solo_sign | channels.shutdown_sign | channels.shutdown_sign_ack | channels.update | channels.update_ack | channels.close_solo_tx | channels.close_solo_sign | channels.slash_tx | channels.slash_sign | channels.settle_tx | channels.settle_sign
params:
error
integer
error code
Yes
It is possible to return an error object in a signing reply. This will abort the ongoing sequence, and the FSM will fall back to the latest mutually-signed state. Currently defined error codes are:
1: validation error
2: conflict (typically, race condition)
3: timeout
4: abort
128...65535: user-defined
Example
Successful operation response
method:
channels.info
params:
channel_id
string
channel ID
Yes
data
object
message data
Yes
params:
event
string
aborted_update
Yes
data:
message
string
Not allowed at current channel state
Yes
code
integer
1018
Yes
If the abort of the update is successful, the client that aborted receives a message for it:
If the other participant had initiated the update that our client had aborted, the other participant's FSM will inform its client of each error, using a conflict
report.
Example
Unsuccessful operation response
method: the request method
params:
channel_id
string
channel ID
Yes
error
object
error data object
Yes
error:
message
string
Rejected
Yes
code
integer
the error code provided
Yes
data
json
error description
Yes
request
json
the failed request
Yes
data:
message
string
Not allowed at current channel state
Yes
code
integer
1018
Yes
If the specified update abort can not be performed now, the request receives the following error:
Last updated