Blockbook API
Blockbook provides REST, websocket and socket.io API to the indexed blockchain.
There are two versions of provided API.
#
API V2API 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.
#
REST APIThe following methods are supported:
- Status
- Get block hash
- Get transaction
- Get transaction specific
- Get address
- Get xpub
- Get utxo
- Get block
- Send transaction
- Tickers list
- Tickers
- Balance history
#
Status pageStatus page returns current status of Blockbook and connected backend.
Response:
#
Get block hashResponse:
Note: Blockbook always follows the main chain of the backend it is attached to. See notes on Get Block below
#
Get transactionGet 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 Bitcoin-type coins:
Response for Ethereum-type coins. There is always only one vin, only one vout, possibly an array of tokenTransfers and ethereumSpecific part. Note that tokenTransfers will also exist for any coins exposing a token interface including Ethereum and Syscoin. Missing is hex field:
A note about the blockTime
field:
- for already mined transaction (
confirmations > 0
), the fieldblockTime
contains time of the block - for transactions in mempool (
confirmations == 0
), the field contains time when the running instance of Blockbook was first time notified about the transaction. This time may be different in different instances of Blockbook.
#
Get transaction specificReturns transaction data in the exact format as returned by backend, including all coin specific fields:
Example response:
#
Get addressReturns balances and transactions of an address. The returned transactions are sorted by block height, newest blocks first.
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 address balances, without any transactions
- tokens: basic + tokens belonging to the address (applicable only to some coins)
- tokenBalances: basic + tokens with balances + belonging to the address (applicable only to some coins)
- txids: tokenBalances + list of txids, subject to from, to filter and paging
- txslight: tokenBalances + list of transaction with limited details (only data from index), subject to from, to filter and paging
- txs: tokenBalances + list of transaction with details, subject to from, to filter and paging
- filter: specifies what tokens (xpub addresses/tokens) are returned by the request (default nonzero)
- inputs: Return transactions sending inputs to this xpub
- outputs: Return transactions sending outputs to this xpub
- =: Return specific numerical vout index
- assetMask: What type of transactions to return (default all)
- all: Returns all types of transactions, base and asset type. The assetMask will represent value of all values OR'ed together see below in = for the masks.
- non-tokens: Return only base coin transactions no asset type. The assetMask will represent value of basecoin.
- token-only: Return only asset type transactions no base coin type. The assetMask will represent value of assetactivate | assetupdate | assetsend | syscoinburntoallocation | assetallocationburntosyscoin | assetallocationburntoethereum | assetallocationmint | assetallocationsend.
- token-transfers: Return only assetallocationsend type transactions. The assetMask will represent value of assetallocationsend.
- non-token-transfers: Return any transactions not of type assetallocationsend. The assetMask will represent value of token-only &^ token-transfers
- =: Apply a custom numerical mask which is a bitmask of the following values:
- basecoin: 1
- assetallocationsend: 2
- syscoinburntoallocation: 4
- assetallocationburntosyscoin: 8
- assetallocationburntoethereum: 16
- assetallocationmint: 32
- assetupdate: 64
- assetsend: 128
- assetactivate: 256
- contract: return only transactions which affect specified contract or asset (applicable only to Ethereum and Syscoin)
Response:
#
Get xpubReturns balances and transactions of an xpub, applicable only for Bitcoin-type coins.
Blockbook supports BIP44, BIP49 and BIP84 derivation schemes. It expects xpub at 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 BIP version is determined by the prefix of the xpub. The prefixes for each coin are defined by fields xpub_magic
, xpub_magic_segwit_p2sh
, xpub_magic_segwit_native
in the trezor-common library. If the prefix is not recognized, Blockbook defaults to BIP44 derivation scheme.
The returned transactions are sorted by block height, newest blocks first.
The optional query parameters:
- page: specifies page of returned transactions, starting from 1. If out of range, Blockbook returns the closest possible page. Tokens are only returned for coins that have token platforms (Syscoin).
- 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/tokens) derived from the xpub, subject to tokens parameter
- tokenBalances: basic + tokens (addresses/tokens) 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/tokens) are returned by the request (default nonzero)
- nonzero: return only addresses/tokens with nonzero balance
- used: return addresses/tokens with at least one transaction
- derived: return all derived addresses/tokens
- filter: specifies what tokens (xpub addresses/tokens) are returned by the request (default nonzero)
- inputs: Return transactions sending inputs to this xpub
- outputs: Return transactions sending outputs to this xpub
- =: Return specific numerical vout index
- assetMask: What type of transactions to return (default all)
- all: Returns all types of transactions, base and asset type. The assetMask will represent value of all values OR'ed together see below in = for the masks.
- non-tokens: Return only base coin transactions no asset type. The assetMask will represent value of basecoin.
- token-only: Return only asset type transactions no base coin type. The assetMask will represent value of assetactivate | assetupdate | assetsend | syscoinburntoallocation | assetallocationburntosyscoin | assetallocationburntoethereum | assetallocationmint | assetallocationsend.
- token-transfers: Return only assetallocationsend type transactions. The assetMask will represent value of assetallocationsend.
- non-token-transfers: Return any transactions not of type assetallocationsend. The assetMask will represent value of token-only &^ token-transfers
- =: Apply a custom numerical mask which is a bitmask of the following values:
- basecoin: 1
- assetallocationsend: 2
- syscoinburntoallocation: 4
- assetallocationburntosyscoin: 8
- assetallocationburntoethereum: 16
- assetallocationmint: 32
- assetupdate: 64
- assetsend: 128
- assetactivate: 256
- contract: return only transactions which affect specified contract or asset (applicable only to Ethereum and Syscoin)
Response:
Note: usedTokens always returns total number of used addresses of xpub.
#
Get utxoReturns 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.
Unconfirmed utxos do not have field height, the field confirmations has value 0 and may contain field lockTime, if not zero.
Coinbase utxos do have field coinbase set to true, however due to performance reasons only up to minimum coinbase confirmations limit (100). After this limit, utxos are not detected as coinbase.
Response:
#
Get blockReturns information about block with transactions, subject to paging.
Response:
Note: Blockbook always follows the main chain of the backend it is attached to. If there is a rollback-reorg in the backend, Blockbook will also do rollback. When you ask for block by height, you will always get the main chain block. If you ask for block by hash, you may get the block from another fork but it is not guaranteed (backend may not keep it)
#
Send transactionSends new transaction to backend.
Response:
or in case of error
#
Tickers listReturns a list of available currency rate tickers for the specified date, along with an actual data timestamp.
The query parameters:
- timestamp: specifies a Unix timestamp to return available tickers for.
Example response:
#
TickersReturns currency rate for the specified currency and date. If the currency is not available for that specific timestamp, the next closest rate will be returned. All responses contain an actual rate timestamp.
The optional query parameters:
- currency: specifies a currency of returned rate ("usd", "eur", "eth"...). If not specified, all available currencies will be returned.
- timestamp: a Unix timestamp that specifies a date to return currency rates for. If not specified, the last available rate will be returned.
Example response (no parameters):
Example response (currency=usd):
Example error response (e.g. rate unavailable, incorrect currency...):
#
Balance historyReturns a balance history for the specified XPUB or address.
Query parameters:
- from: specifies a start date as a Unix timestamp
- to: specifies an end date as a Unix timestamp
The optional query parameters:
- fiatcurrency: if specified, the response will contain fiat rate at the time of transaction. If not, all available currencies will be returned.
- groupBy: an interval in seconds, to group results by. Default is 3600 seconds.
Example response (fiatcurrency not specified):
Example response (fiatcurrency not specified):
Example response (fiatcurrency=usd):
Example response (fiatcurrency=usd&groupBy=172800):
The value of sentToSelf
is the amount sent from the same address to the same address or within addresses of xpub.
#
Websocket APIWebsocket interface is provided at /websocket/
. The interface can be explored using Blockbook Websocket Test Page found at /test-websocket.html
.
The websocket interface provides the following requests:
- getInfo
- getBlockHash
- getAccountInfo
- getAccountUtxo
- getTransaction
- getTransactionSpecific
- getBalanceHistory
- getCurrentFiatRates
- getFiatRatesTickersList
- getFiatRatesForTimestamps
- estimateFee
- sendTransaction
- ping
The client can subscribe to the following events:
subscribeNewBlock
- new block added to blockchainsubscribeNewTransaction
- new transaction added to blockchain (all addresses)subscribeAddresses
- new transaction for given address (list of addresses)subscribeFiatRates
- new currency rate ticker
There can be always only one subscription of given event per connection, i.e. new list of addresses replaces previous list of addresses.
The subscribeNewTransaction event is not enabled by default. To enable support, blockbook must be run with the -enablesubnewtx
flag.
Note: 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 communication format
Example for subscribing to an address (or multiple addresses)
#
Legacy API V1The 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#
Socket.io APISocket.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.3.5) also accessible without the /v1/ prefix, however in the future versions the version less access will be removed.