newBlocks
newBlocks provides a stream of all new blocks as they propagate through the BDN. It is intended for use cases that are not latency-sensitive and require fully validated blocks. For lower-latency use cases, use bdnBlocks.
Service available via Gateway and Cloud API.
Note: Gateway must have a node connection to both Consensus Layer and Execution Layer as well as be using the eth-ws-uristartup argument (see How to connect Go-Gateway to consensus layer).
Stream Endpoint
Method:
newBlocksCloud-API Endpoint:
wss://<region>.eth.blxrbdn.com/wsGateway-API Endpoint:
ws://127.0.0.1:28333/wsRequest type:
gRPC,WSS
Parameters
include
Fields to include in the block stream.
hash,header,transactions,future_validator_info,withdrawals
[Default: all] future_validator_info contains validator addresses for future blocks and indicates whether the validators are connected to the BDN (currently only supported in BSC) withdrawals
contains withdrawals for ETH block
parsedTxs
Controls whether transactions in each block are returned as fully parsed JSON objects (true) or as raw, unparsed RLP payloads (false). Disabling parsing reduces server work and improves delivery latency.
Type: boolean
[Default: false]
Examples (Websocket)
Cloud-API
## ETH Example
wscat -c wss://virginia.eth.blxrbdn.com/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
> {"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": [""]}]}
< ......
var fs = require('fs');
const WebSocket = require('ws');
// Enterprise users can follow line 5-16
const ws = new WebSocket(
'wss://virginia.eth.blxrbdn.com/ws', // for ETH
// use 'wss://virginia.bsc.blxrbdn.com/ws', //for BSC
{
headers: {
"Authorization" : <YOUR-AUTHORIZATION-HEADER>
},
// Add the following line if you work with IP instead of DNS
// rejectUnauthorized: false,
}
);
// const ws = new WebSocket(
// "wss://api.blxrbdn.com/ws",
// {
// headers: {
// "Authorization" : <YOUR-AUTHORIZATION-HEADER>
// },
// rejectUnauthorized: false,
// }
// );
function proceed() {
// ETH Example
ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"]}]}`);
}
function handle(nextNotification) {
console.log(nextNotification.toString()); // or process it generally
}
ws.on('open', proceed);
ws.on('message', handle);Gateway-API (gRPC)
Response (Block Event)
Last updated