Websocket
Connect
In the public channel, when the client successfully connects to the ZkLink node, the server will return a message with ID 0, which contains the listen_key
automatically created by the server for the connection:
The server will send ping
frame to the client every two minutes, and the client should reply the pong
frame within 10 minutes, otherwise the connection will be automatically disconnected.
Public Topics
Topic of transaction execution results:
txExecuteResult@{sub_account_id}
, for example whensub_account_id
is1
, the topic will betxExecuteResult@1
;full exit event:
fullExitEvent@{sub_account_id}
, for example whensub_account_id
is1
, the topic will befullExitEvent@1
.
Subscribe & Unsubscribe Topics
The client can subscribe and unsubscribe to topics at any time after connecting, and only needs to send a request to the service:
where the value of method
can be subscribe
or unSubscribe
. The id in the response content is an unsigned integer, which serves as the unique identifier of the communication. It also contains the value of the currently subscribed topic list.
Query Topic
GET /api/topics/{listen_key}
The client can use the listen_key
(returned when the Websocket first connection) to query the topic
list of its corresponding Websocket connection. The return value is:
When the Websocket connection corresponding to listen_key
is disconnected, null
is returned.
Data Push
Transaction Execution Results
topic: txExecuteResult@{sub_account_id}
Name | Type | Describe |
---|---|---|
type | String | Event type |
tx_hash | The tx hash on L1 | |
tx | Transaction detail | |
receipt | struct | The transaction status after received |
> executed | bool | The transaction finished executing or not |
> executedTimestamp | Option | The Unix microsecond timestamp when transaction excute, when executed is false, the value will be null |
> success | bool | The transaction executed successfull or not |
> failReason | Option | The reason that transaction execute fail, the value will be null if transaction execute success |
> block | Option | Block height that contains the transaction, it will be null if success is false |
> index | Option | The transaction index in the block, if value will be null if success is false |
updates | StateUpdateResp array | Update event |
Full Exit Event
topic: fullExitEvent@{sub_account_id}
Name | Type | Description |
---|---|---|
type | String | Event type |
tx_hash | The tx hash on L1 | |
tx | FullExit transaction |
For example:
Last updated