**Blockbook** provides REST, websocket and socket.io API to the indexed blockchain.
There are two versions of provided API.
## Legacy API V1
The legacy API is a compatible subset of API provided by **Bitcore Insight**. It supports only Bitcoin-type coins. The details of the REST/socket.io requests can be found in the Insight's documentation.
### REST API
```
GET /api/v1/block-index/<blockheight>
GET /api/v1/tx/<txid>
GET /api/v1/address/<address>
GET /api/v1/utxo/<address>
GET /api/v1/block/<blockheight|blockhash>
GET /api/v1/estimatefee/<numberofblocks>
GET /api/v1/sendtx/<hextxdata>
POST /api/v1/sendtx (hex tx data in request body)
```
### Socket.io API
Socket.io interface is provided at `/socket.io/`. The interface also can be explored using Blockbook Socket.io Test Page found at `/test-socketio.html`.
The legacy API is provided as is and will not be further developed.
The legacy API is currently (Blockbook v0.2.1) also accessible without the */v1/* prefix, however in the future versions the version less access will be removed.
## API V2
API V2 is the current version of API. It can be used with all coin types that Blockbook supports. API V2 can be accessed using REST and websocket interface.
Common principles used in API V2:
- all amounts are transferred as strings, in the lowest denomination (satoshis, wei, ...), without decimal point
- empty fields are omitted. Empty field is a string of value *null* or *""*, a number of value *0*, an object of value *null* or an array without elements. The reason for this is that the interface serves many different coins which use only subset of the fields. Sometimes this principle can lead to slightly confusing results, for example when transaction version is 0, the field *version* is omitted.
Get transaction returns "normalized" data about transaction, which has the same general structure for all supported coins. It does not return coin specific fields (for example information about Zcash shielded addresses).
Response for Ethereum-type coins. There is always only one *vin*, only one *vout*, possibly an array of *tokentransfers* and *ethereumspecific* part. Missing is *hex* field:
Returns balances and transactions of an xpub, applicable only for Bitcoin-type coins. Xpub must be in BIP44, BIP49 or BIP84 format (the BIP number is detected by the prefix of xpub) with level 3 derivation path, i.e. *m/purpose'/coin_type'/account'/*. Blockbook completes the *change/address_index* part of the path when deriving addresses. The returned transactions are sorted by block height, newest blocks first.
```
GET /api/v2/xpub/<xpub>[?page=<page>&pageSize=<size>&from=<blockheight>&to=<blockheight>&details=<basic|tokens|tokenBalances|txids|txs>&tokens=<nonzero|used|derived>]
```
The optional query parameters:
- *page*: specifies page of returned transactions, starting from 1. If out of range, Blockbook returns the closest possible page.
- *pageSize*: number of transactions returned by call (default and maximum 1000)
- *from*, *to*: filter of the returned transactions *from* block height *to* block height (default no filter)
- *details*: specifies level of details returned by request (default *txids*)
- *basic*: return only xpub balances, without any derived addresses and transactions
- *tokens*: *basic* + tokens (addresses) derived from the xpub, subject to *tokens* parameter
- *tokenBalances*: *basic* + tokens (addresses) derived from the xpub with balances, subject to *tokens* parameter
- *txids*: *tokenBalances* + list of txids, subject to *from*, *to* filter and paging
- *txs*: *tokenBalances* + list of transaction with details, subject to *from*, *to* filter and paging
- *tokens*: specifies what tokens (xpub addresses) are returned by the request (default *nonzero*)
- *nonzero*: return only addresses with nonzero balance
- *used*: return addresses with at least one transaction
Note: *totalTokens* always returns total number of **used** addresses of xpub.
#### Get utxo
Returns array of unspent transaction outputs of address or xpub, applicable only for Bitcoin-type coins. By default, the list contains both confirmed and unconfirmed transactions. The query parameter *confirmed=true* disables return of unconfirmed transactions. The returned utxos are sorted by block height, newest blocks first. For xpubs the response also contains address and derivation path of the utxo.
Websocket interface is provided at `/websocket/`. The interface also can be explored using Blockbook Websocket Test Page found at `/test-websocket.html`.