block

Subscribes/Unsubscribes to every new block or a specific block number.

Make sure you're connected.

Request

Every new block:

{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["block"]}

Specific block_number:

{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["block",{"number":7452758}]}
FieldTypeDescription
numbernumberThe block number.

Response

"result": {
  "blockchainId": "1c9c969065fcd1cf",
  "number": 7549499,
  "hash": "0x9d5a5b...",
  "parentHash": "0x33b18c...",
  "nonce": 2322883515373825000,
  "miner": "0x04668ec2f57cc15c381b461b9fedab5d451c8f7f",
  "difficulty": 1868847723100634,
  "totalDifficulty": 9794639309953347000000,
  "size": 26080,
  "gasLimit": 8000000,
  "gasUsed": 6716792,
  "timestamp": 1555023036000,
  "timestampNanoseconds": 0,
  "numTransactions": 107,
  "numUncles": 0,
  "reward": 2057342694413545700,
  "transactionHashes": null,
  "optionalProperties": {
    "logsBloom": "0xea0030...",
    "receiptsRoot": "0x4b001f...",
    "sha3Uncles": "0x1dcc4d...",
    "extraData": "0x706f6f...",
    "author": null,
    "transactionsRoot": "0x53d558...",
    "stateRoot": "0x4e9b0e...",
    "mixHash": "0xfeeb1d..."
  }
}

Response Data

FieldTypeDescription
difficultystringA scalar value corresponding to the difficulty level of this block.
extraDatastringAn arbitrary byte array containing data relevant to this block.
gasLimitstringThe scalar value equal to the current limit of gas expenditure per block.
gasUsedstringThe scalar value equal to the total gas used in transactions in this block.
hashstringBlock header hash.
logsBloomstringThe Bloom filter composed from indexable information (logger address and log topics) contained in each log entry from the receipt of each transaction in the transactions list.
minerstringThe 160-bit address to which all fees collected from the successful mining of this block
be transferred.
mixHashstringThe 256-bit hash which proves combined with the nonce that a sufficient amount of computation has been carried out on this block.
noncestringThe 64-bit hash which proves combined with the mix-hash that a sufficient amount of computation has been carried out on this block
numTransactionsnumberNumber of transactions contained in the block.
numberstringThe scalar value equal to the number of ancestor blocks.
parentHashstringThe Keccak 256-bit hash of the parent block’s header.
receiptsRootstringThe Keccak 256-bit hash of the root node of the trie structure populated with the receipts of each transaction in the transactions list portion of the block.
sha3UnclesstringThe combined hash of alluncles for a given parent.
sizenumberThe size of the block in bytes.
stateRootstringThe Keccak 256-bit hash of the root node of the state trie, after all transactions are executed and finalisations applied.
timestampstringThe value equal to the reasonable output of Unix’s time() at this block’s inception.
totalDifficultystringThe total difficulty of the chain.
transactionsRootstringThe Keccak 256-bit hash of the
root node of the trie structure populated with each transaction in the transactions list portion of the block.

Example

const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io', {headers: {x-api-key:'<api_key>'}});

ws.on('open', () => {
  ws.send(JSON.stringify({
      jsonrpc: '2.0',
      method: 'subscribe',
      params: ['block'],
      id: 1,
    }));
});

ws.on('message', data => {
  console.log(JSON.stringify(JSON.parse(data), null, 2));
});

Supported Blockchains

BlockchainNetworkSlug (x-amberdata-blockchain-id)
BitcoinMainnetbitcoin-mainnet
Bitcoin CashMainnetbitcoin-abc-mainnet
LitecoinMainnetlitecoin-mainnet
ZcashMainnetzcash-mainnet
EthereumMainnetethereum-mainnet