Websocket

wss://api.chain49.com/{blockchain}/websocket

The Blockbook Websocket interface allows clients to listen for events on the blockchain instead of polling for any changes which is a lot less efficient.

Authentication works the same as on HTTP routes. If you choose to give the API key as URL parameter then your URL will look like this: wss://api.chain49.com/{blockchain}/{api_key}/websocket

🚧

Many Websocket implementations do not support adding/changing the HTTP request headers and therefore require an alternative method for providing the API key.

Websocket communication format (based on JSON-RPC spec)

{  
  "id": "49", 
  "method": "getInfo",  
  "params": "<same params as in the equivalent REST API calls>"
}

The following methods are available:

Info / UtilFiat Rates (from CoinGecko)TransactionsAccounts & Blocks
pinggetCurrentFiatRatesgetTransactiongetAccountInfo
getInfogetFiatRatesTickersListgetTransactionSpecificgetAccountUtxo
getFiatRatesForTimestampssendTransactiongetBalanceHistory
estimateFeegetBlockHash

Examples for wscat:

C49_API_KEY=INSERT_YOUR_KEY_HERE

wscat -c wss://api.chain49.com/ethereum/$C49_API_KEY/websocket

# wait for connect, then paste example request objects into wscat prompt

# example request "getInfo"
{ "id": "49", "method": "getInfo", "params": "" }

# example req with params "getAccountInfo"
{ "id": "49", "method": "getAccountInfo", "params": { "descriptor": "0xba98d6a5ac827632e3457de7512d211e4ff7e8bd", "details": "txids" } }

# example subscription
{ "id": "49", "method": "subscribeNewTransaction", "params": "" }

Subscriptions

In addition to requesting info with the methods described above, the client can subscribe to the following events:

subscribeNewBlock - new block added to blockchain
subscribeNewTransaction - new transaction added to blockchain (all addresses)
subscribeAddresses - new transaction for a given address (list of addresses) added to mempool
subscribeFiatRates - new currency rate ticker

Example for subscribing to an address (or multiple addresses):

{  
  "id":"1",  
  "method":"subscribeAddresses",  
  "params":{  
    "addresses":["mnYYiDCb2JZXnqEeXta1nkt5oCVe2RVhJj", "tb1qp0we5epypgj4acd2c4au58045ruud2pd6heuee"]  
   }  
}

There can be always only one subscription of given event per connection, i.e. new list of addresses replaces previous list of addresses.

πŸ“˜

If there is reorg on the backend (blockchain), you will get a new block hash with the same or even smaller height if the reorg is deeper

Websocket Playground

A great way to explore the Websocket API is with our Websocket playground where you can try out every method and subscription that is possible.

You can find the playground here: https://api.chain49.com/websocket-playground