Skip to content

æternity node channel WebSocket API examples

The JSON-RPC section provides examples of state channel's communication via the WebSocket API. The examples are generated from æternity node's integration tests and represent real interaction with the node.

Different APIs

Currently there is 1 API protocol that is supported:


Legacy protocol was removed.

You can find API specific examples in the corresponding directories.

Anatomy of an example

Each example pursues a specific use case. Examples are broken down into sections each one of which describes a single action. Example for a section would be:

responder <--- node (2019-03-13 11:04:47.10)
  "jsonrpc": "2.0",
  "method": "",
  "params": {
    "channel_id": null,
    "data": {
      "event": "channel_open"
  "version": 1

Each section has an participant, an action, a timestamp and a code snippet. In the above example the responder receives from its node the message.


Channels have two participants: an initiator and a responder. For clarity each section has an explicit actor. Each participant has one's own node and has a WebSocket connection to it. The two nodes open a noise protocol connection between themselves: initiator's node connects to a host and port that the responder provides.

+-----------+               +------+
|           |    WebSocket  |      |
| initiator +---------------+ node |
|           |               |      |
+-----------+               +--+---+
                               | noise
+-----------+               +--+---+
|           |    WebSocket  |      |
| responder +---------------+ node |
|           |               |      |
+-----------+               +------+


Actions are either opening a WebSocket connection, receiving a message or sending a message. All messages are sent and received from one's own node via the opened WebSocket connection. The node has the responsibility to send messages to the other participant's node via the noise protocol connection they persist.

Open a WebSocket connection

An opening message includes all the needed parameters and looks like this:

initiator opens a WebSocket connection (2019-03-13 11:04:45.887)
Sending and receiving a message

In the section, right after the participant, there is an arror indicating the direction of the message:

  • <--- node means that a message had been received from the node
  • ---> node means that a message had been sent to the node
Information log messages

Some WebSocket events represent important milestones regarding the example logic and those are followed by a special information message that is a comment of what had just happened. They look like this:

responder info

Received an WebSocket opening request

Continuous example

There are two types of examples:

  • Those that show a full open-close scenario (most of the examples)
  • Those that are built on top of the previous ones' state (continuous) These have one single opening of the state channel and the following examples are focused on specific actions