bdnBlocks is a stream of all new blocks as they are propagated in the BDN. The blocks published in the bdnBlocks stream may include blocks that will not be accepted on chain. This stream offers significant performance speed over the newBlocks stream (from the Gateway or the node).
Service available on both Cloud-API and Gateway-API.
[Default: all]
future_validator_infocontains 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
blockchain_network
Use BSC-Mainnet
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
Gateway-API
Response (Block Event)
This response is for when parsedTxs is set to true in the stream subscription
var fs = require('fs');
const WebSocket = require('ws');
// Enterprise users can follow line 5-16
const ws = new WebSocket(
'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,
}
);
function proceed() {
// BSC Example (only available at endpoint wss://<region>.bsc.blxrbdn.com/ws)
ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["bdnBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"}]}`);
}
function handle(nextNotification) {
console.log(nextNotification.toString()); // or process it generally
}
ws.on('open', proceed);
ws.on('message', handle);
import asyncio, json, ssl, websockets
async def main():
auth_key = "YOUR_AUTHORIZATION_HEADER"
uri = 'wss://virginia.bsc.blxrbdn.com/ws'
async with websockets.connect(
uri,
header=["Authorization:{}".format(auth_key)],
sslopt={"cert_reqs": ssl.CERT_NONE},
) as websocket:
# BSC Example (only available at endpoint wss://<region>.bsc.blxrbdn.com/ws)
subscribe_request = {"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["bdnBlocks", {"include": ["hash"]}, "blockchain_network": "BSC-Mainnet"]}
await websocket.send(json.dumps(subscribe_request))
response = await websocket.recv()
subscription_id = json.loads(response)["result"]
while True:
next_notification = await websocket.recv()
print(next_notification) # or process it generally
unsubscribe_request = {
"jsonrpc": "2.0",
"id": 2,
"method": "unsubscribe",
"params": [subscription_id]
}
await websocket.send(json.dumps(unsubscribe_request))
if __name__ == '__main__':
asyncio.run(main())
package main
import (
"crypto/tls"
"fmt"
"github.com/gorilla/websocket"
"net/http"
)
func main() {
dialer := websocket.DefaultDialer
// Add the following lines if you work with IP instead of DNS
// tlsConfig := &tls.Config{
// Certificates: []tls.Certificate{cert},
// InsecureSkipVerify: true,
// }
// dialer.TLSClientConfig = tlsConfig
// Enterprise users can follow line 20
wsSubscriber, _, err := dialer.Dial("wss://virginia.eth.blxrbdn.com/ws", http.Header{"Authorization": []string{<YOUR-AUTHORIZATION-HEADER>}})
// Non Enterprise users can follow line 23
// wsSubscriber, _, err := dialer.Dial("wss://api.blxrbdn.com/ws", http.Header{"Authorization": []string{<YOUR-AUTHORIZATION-HEADER>}})
if err != nil {
fmt.Println(err)
return
}
// BSC Example (only available at endpoint wss://<region>.bsc.feed.blxrbdn.com:28333)
subRequest := `{"id": 1, "method": "subscribe", "params": ["bdnBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"}]}`
err = wsSubscriber.WriteMessage(websocket.TextMessage, []byte(subRequest))
if err != nil {
fmt.Println(err)
return
}
for {
_, nextNotification, err := wsSubscriber.ReadMessage()
if err != nil {
fmt.Println(err)
}
fmt.Println(string(nextNotification)) // or process it generally
}
}