block [OND]

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}]}

Field

Type

Description

number

number

The 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

Field

Type

Description

difficulty

string

A scalar value corresponding to the difficulty level of this block.

extraData

string

An arbitrary byte array containing data relevant to this block.

gasLimit

string

The scalar value equal to the current limit of gas expenditure per block.

gasUsed

string

The scalar value equal to the total gas used in transactions in this block.

hash

string

Block header hash.

logsBloom

string

The 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.

miner

string

The 160-bit address to which all fees collected from the successful mining of this block
be transferred.

mixHash

string

The 256-bit hash which proves combined with the nonce that a sufficient amount of computation has been carried out on this block.

nonce

string

The 64-bit hash which proves combined with the mix-hash that a sufficient amount of computation has been carried out on this block

numTransactions

number

Number of transactions contained in the block.

number

string

The scalar value equal to the number of ancestor blocks.

parentHash

string

The Keccak 256-bit hash of the parent block’s header.

receiptsRoot

string

The 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.

sha3Uncles

string

The combined hash of alluncles for a given parent.

size

number

The size of the block in bytes.

stateRoot

string

The Keccak 256-bit hash of the root node of the state trie, after all transactions are executed and finalisations applied.

timestamp

string

The value equal to the reasonable output of Unix’s time() at this block’s inception.

totalDifficulty

string

The total difficulty of the chain.

transactionsRoot

string

The 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));
});