Subscribe API

The Subscribe API is sometimes called the publish/subscribe or Event-Driven API. The biggest difference between Event-Driven and regular REST API is not only technical. In practice, a two-way streaming connection is used, which means that not only can the client request the server for a data update, (and also potential updates) but also the server can notify the client about new data instantly as it arrives.

Lisk Service leverages the two-way communication approach by utilizing the WebSocket library responsible for updating users about changes in the blockchain network and markets.

Access paths and compatibility

The blockchain update API can be accessed by the following path https://service.lisk.io/blockchain.

If you are interested in accessing the testnet network, this can be accomplished by using the https://testnet-service.lisk.io/blockchain endpoint.

Important: The Lisk Service WebSocket API uses the socket.io library. This implementation is compatible with the version 2.0 of the socket.io library. Using the wrong major version might result in a broken connection and messages not being passed.

The specification below contains numerous examples how to use the API in practice.

Endpoint logic

The logic of the endpoints is derived as follows: the method naming is always based on the following pattern: <action>.<entity>, where the action is equivalent to method type performed on the server (ie. update) and entity is a part of the application logic, ex. accounts, transactions.

Responses

All responses are returned in the JSON format - application/json.

Each API request has the following structure:

{
    "data": {}, // Contains the requested data
    "meta": {
        "count": <integer>, // number of items
        "timestamp": <timestamp>, // timestamp in seconds
        ...               // other metadata
    },
}

Date Format

On the contrary to the original Lisk Core API, all timestamps used by the Lisk Service are in the UNIX timestamp format. The blockchain dates are always expressed as integers and the epoch date is equal to the number of seconds since 1970-01-01 00:00:00.

Example of a client implementation

Node.js
const io = require('socket.io-client');
const connection = io.connect('https://service.lisk.io/blockchain', { transports: ['websocket'] });
connection.on('update.block', (block) => { (...) });

Available subscriptions

update.block

Updates about a newly forged block with its all data.

Response
{
    id: "6286637019365913992",
    version: 1,
    timestamp: 146010410,
    height: 12659996,
    numberOfTransactions: 0,
    totalAmount: "0",
    totalFee: "0",
    reward: "100000000",
    payloadLength: 0,
    payloadHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
    generatorPublicKey: "bfd925085aeb9d2d21973363d6a3e8d394b25116e252b4db701e3dabe319b016",
    blockSignature: "7e57deaf35bdf6ec804a402f04aaca6e70ecb1a928d28e98277219fa9caa5a770b0dea3ecf402cdfc35c7b8a84d1611a5b794d70bf3c29d51c28b8ded3b5920c",
    confirmations: 1,
    totalForged: "100000000",
    generatorAddress: "3865707283477759335L",
    previousBlockId: "9424602178629894603",
    unixTimestamp: 1610119610
}

update.round

Updates about the forging delegates for the next round.

Response
{
    "data": [
        {
            "address": "1492771550241913308L",
            "publicKey": "04c531ebe3b3c910abe89ad758636554396c92979e8c92dc04107404effac0fd",
            "username": "genesis_66"
        }
        ...
    ],
    "meta": {
        "count": 25,
        "timestamp": 1573059291
    }
}

update.forgers

Updates the current forgers' list, so the current forger is in the first position.

Response
{
    "data": [
        {
            "address": "1492771550241913308L",
            "publicKey": "04c531ebe3b3c910abe89ad758636554396c92979e8c92dc04107404effac0fd",
            "username": "genesis_66"
        }
        ...
    ],
    "meta": {
        "count": 25,
        "timestamp": 1573059291
    }
}

update.transactions.confirmed

Updates about transactions from the last block.

Response
{
    "data": [
        {
            "id": "12761961644475138241",
            "amount": "100000000",
            "fee": "10000000",
            "type": 0,
            "height": 26998,
            "blockId": "3226008563694255110",
            "timestamp": 1573059285,
            "senderId": "16313739661670634666L",
            "senderPublicKey": "c094ebee7ec0c50ebee32918655e089f6e1a604b83bcaa760293c61e0f18ab6f",
            "recipientId": "16313739661670634666L",
            "recipientPublicKey": "c094ebee7ec0c50ebee32918655e089f6e1a604b83bcaa760293c61e0f18ab6f",
            "signature": "8b93bddbc51411f45dd2be352496f0b4a8dcc37bdf632eb311d292c7f2de75e5182c1ac554f54031313a5c7f9fcfa091dee7790aa40c2ee96091ba52710b600e",
            "signatures": [],
            "confirmations": 1,
            "asset": {}
        },
        ...
    ],
    "meta": {
        "count": 4,
        "timestamp": 1573059291
    }
}