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 |
| A scalar value corresponding to the difficulty level of this block. |
extraData |
| An arbitrary byte array containing data relevant to this block. |
gasLimit |
| The scalar value equal to the current limit of gas expenditure per block. |
gasUsed |
| The scalar value equal to the total gas used in transactions in this block. |
hash |
| Block header hash. |
logsBloom |
| 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 |
| The 160-bit address to which all fees collected from the successful mining of this block |
mixHash |
| The 256-bit hash which proves combined with the nonce that a sufficient amount of computation has been carried out on this block. |
nonce |
| 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 of transactions contained in the block. |
number |
| The scalar value equal to the number of ancestor blocks. |
parentHash |
| The Keccak 256-bit hash of the parent block’s header. |
receiptsRoot |
| 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 |
| The combined hash of alluncles for a given parent. |
size |
| The size of the block in bytes. |
stateRoot |
| The Keccak 256-bit hash of the root node of the state trie, after all transactions are executed and finalisations applied. |
timestamp |
| The value equal to the reasonable output of Unix’s time() at this block’s inception. |
totalDifficulty |
| The total difficulty of the chain. |
transactionsRoot |
| The Keccak 256-bit hash of the |
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
Blockchain | Network | Slug (x-amberdata-blockchain-id) |
---|---|---|
Bitcoin | Mainnet | bitcoin-mainnet |
Bitcoin Cash | Mainnet | bitcoin-abc-mainnet |
Litecoin | Mainnet | litecoin-mainnet |
Zcash | Mainnet | zcash-mainnet |
Ethereum | Mainnet | ethereum-mainnet |