Links

newBlocks

Available on 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).
Name: newBlocks
newBlocks is a stream of all new blocks as they are propagated in the BDN.

Options

Key
Description
Values
include
Fields to include in the block stream.
hash,header,transactions,future_validator_info
[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)

Examples (Websocket)

Cloud-API

wscat
Node.js
Python
Golang
## 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": ["hash"]}]}
< ......
​
​
## BSC Example
wscat -c wss://virginia.bsc.blxrbdn.com/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
> {"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"}]}
< ......
​
​
## Polygon Example
wscat -c wss://virginia.polygon.blxrbdn.com/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
> {"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "Polygon-Mainnet"}]}
< ......
​
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
// use 'wss://virginia.polygon.blxrbdn.com/ws', // for Polygon
{
headers: {
"Authorization" : <YOUR-AUTHORIZATION-HEADER>
},
// Add the following line if you work with IP instead of DNS
// rejectUnauthorized: false,
}
);
​
// Non Enterprise users should follow line 19-27
// 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"]}]}`);
​
// BSC Example (only available at endpoint wss://<region>.bsc.blxrbdn.com/ws)
// ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"}]}`);
​
// Polygon Example (only available at endpoint wss://<region>.polygon.blxrbdn.com/ws)
// ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "Polygon-Mainnet"}]}`);
}
​
​
function handle(nextNotification) {
console.log(nextNotification.toString()); // or process it generally
}
​
ws.on('open', proceed);
ws.on('message', handle);
# Python version 3.7 or higher required
import asyncio, json, websockets
​
async def main():
try:
# Enterprise users and above
uri = "wss://virginia.eth.blxrbdn.com/ws"
# Non Enterprise users
# uri="wss://api.blxrbdn.com/ws"
auth_key = "YOUR_AUTHORIZATION_HEADER"
async with websockets.connect(
uri,
header=["Authorization:{}".format(auth_key)],
# Add the following line if you work with IP instead of DNS
# sslopt={"cert_reqs": ssl.CERT_NONE}
) as websocket:
# ETH Example
subscription_request = json.dumps({
"jsonrpc": "2.0",
"method": "subscribe",
"params": ["newBlocks", {"include": ["hash"]}],
"id": 1,
})
# BSC Example (only available at endpoint wss://<region>.bsc.blxrbdn.com/ws)
# subscription_request = json.dumps({"id": 1, "jsonrpc": "2.0","newBlocks", "method": "subscribe","params": ["newBlocks", {"include": ["hash"]}], "blockchain_network": "BSC-Mainnet"})
# Polygon Example (only available at endpoint wss://<region>.polygon.blxrbdn.com/ws)
# subscription_request = json.dumps({"id": 1, "jsonrpc": "2.0","newBlocks", "method": "subscribe","params": ["newBlocks", {"include": ["hash"]}], "blockchain_network": "Polygon-Mainnet"})
await websocket.send(subscription_request)
while True:
response = await websocket.recv()
print(response) # or process it generally
except Exception as e:
print(f'Connection failed, Reason: {e}')
​
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
}
​
// ETH Example
subRequest := `{"id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"]}]}`
​
// BSC Example (only available at endpoint wss://<region>.bsc.feed.blxrbdn.com:28333)
// subRequest := `{"id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"}]}`
​
// Polygon Example (only available at endpoint wss://<region>.polygon.blxrbdn.com:28333)
// subRequest := `{"id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "Polygon-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
}
}
​

Response (Block Event)

Block Event
<<< {"jsonrpc": "2.0", "id": null, "method": "subscribe",
"params": {"subscription": "213883fe-b3e2-4da2-b9ba-196a82df8628",
"result": {"hash": "0x079b7f1b5a68d4301cf97df2f81c406aa598dd508e2d1908974b95ddd61a4156",
"header": {"parentHash": "0xafef6c6bd1049febe85834aa84735f81f2e81efd55d85a1076aae0adceba16de",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"miner": "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
"stateRoot": "0x13f4a37eb7d0ca8ea309a631e51cca86eaa1b9765a2e6a9eb1614ddcf4ea57e4",
"transactionsRoot": "0x33d0f3c1ce4e3be6346738465cafc727f3500990c881d6fe4821567504badfd5",
"receiptsRoot": "0xad4fe2b36823a0b57f1c640d115eacc8cc1e64c73e49f89a131f206457afbf9f",
"logsBloom": "0x3862455e6027e5863992de359e89bd33e91312891441903f715503c922420904c00e77b054483930423b7a0b5aa4433342b5c096fb3a0883a970d882b9ac02104582cab5eb046e62c9ca17acba8268e25c103107216cec48bc432d78b54927991c5147080a5781c028102040a28ab8d016439e6f8a4804b44c15c3fa85873c204ab8938d450f702ec2444f5a83028586683439ff6de3e57be46c295514527dbcc717f08804c1ac022fcccac7c058d447122e109294a38c3b1a2a676c9814c6913200414e638eb046ed244035875a0c2e446132bd450223952a9bbcd694666884a03db1340b8010dfaae464948a9b4ae524ff8a942258445c73ce176bee981b7d",
"difficulty": "0xc39780fb04af3",
"number": "0xab05c3",
"gasLimit": "0xbdfca5",
"gasUsed": "0xbdb8e3",
"timestamp": "0x5fa62290",
"extraData": "0x65746865726d696e652d6575312d36",
"mixHash": "0x3cd96f6536c1cc745ce9a4f767d65a94b64392bc787e029e7c16339641265b0a",
"nonce": "0x327b58b8b7216cf5"},
"future_validator_info":[{"block_height":22460216,
"wallet_id":"0x295e26495cef6f69dfa69911d9d8e4f3bbadb89b",
"accessible":true},
{"block_height":22460217,
"wallet_id":"0x2d4c407bbe49438ed859fe965b140dcf1aab71a9",
"accessible":false}],
"transactions": [{"from": "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
"gas": "0xc350",
"gasPrice": "0x3b9aca00",
"hash": "0x587a2db59d1af16aa03521a711c3db5b443e5d05cfc72eccadb89c99380f7da0",
"input": "0x",
"nonce": "0x1b8a09b",
"value": "0x54fbe53cd2d1338",
"v": "0x25",
"r": "0x41f3261e25a3e77abd4b0bd4f21cfc2d92ca2d52ff9c663c9a68c6a382115dac",
"s": "0x4350bb6f770bb3363094774fe36478b20013c705f4041fc1bcd0f9fe520c9a23",
"to": "0x190aab185dbf089b1c5cf06a4f13421c14fc18fa"},
...
{"from": "0xc88f7666330b4b511358b7742dc2a3234710e7b1",
"gas": "0x5208",
"gasPrice": "0x7aef40a00",
"hash": "0x92df6598e3a2bc9550898fd7b3322594228e513c0098333bbefd6784a1aa90db",
"input": "0x",
"nonce": "0x6827c",
"value": "0x36e9c396c89e000",
"v": "0x25",
"r": "0x1653aae7a09b85b923b4602f69886c816f470f9b5167d16f2cbb963d00345583",
"s": "0x2c429419c8f23172d4fe4177f796daacf6cfccd9d1545d62957e13fa4af933db",
"to": "0x844359bf8d5fa20f32b0d679527adb93d6255abf"}],
"uncles": []}}}

Examples - gRPC

Gateway-API
package main
​
import (
"context"
"fmt"
pb "github.com/bloXroute-Labs/gateway/v2/protobuf"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"time"
)
​
func main() {
// gRPC server default values
gatewayHostIP := "localhost"
gatewayGRPCPort := 5001
​
// Open gRPC connection to Gateway.
conn, _ := grpc.Dial(
fmt.Sprintf("%v:%v", gatewayHostIP, gatewayGRPCPort),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
​
// Use the Gateway client connection interface.
client := pb.NewGatewayClient(conn)
​
// create context and defer cancel of context
callContext, cancel := context.WithTimeout(context.Background(), 24*time.Hour)
defer cancel()
​
// Create a subscription using the stream-specific method and request.
stream, _ := client.NewBlocks(callContext, &pb.BlocksRequest{})
​
for {
subscriptionNotification, err := stream.Recv()
if err == nil {
fmt.Println(subscriptionNotification) // or process it generally
}
}
}

Response (Block Event)

<<< hash: "0x11f...ce2d"
subscription_id: "d1d6349e-40e8-4868-83aa-7f06b9cb3172"
header: {
parent_hash: "0xf254c84238d1e5c9aca356a7ad01a7dc75c7012c8cb06a43510bdc486027374c",
sha3_uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
miner: "0x1ad91ee08f21be3de0ba2ba6918e714da6b45836",
state_root: "0xa80ba46395c5cd93a2122296207ed5433a6f0bafdf31a9db43d641a7bc764e55",
transactions_root: "0x7588844493391e8503a966f4720d85f83a3e672e314a122db2bb6769b214c90b",
receipts_root: "0x8a6aaba9d857189db685a1bb9d179f1cdca9b1c06bd77ff851d31e90734c70bf",
logs_bloom: "0xd0fa0757dcfb97f75b80a4f4ffc24bdef632117a9ebcbabb65abf679d77f5bbf96cdc19a58f142755d85db83ef7c13f61f6784706b41fbc9fe56fb2ab7ecedcfc9eeedd34149fd7f2ade66cf7df4f6f5928ba98cafde24ffa4e37fdfe0cc7dbf1fb5e43b42687836fc7c1e958f11edf47f77b9f2b0357e707a72fdf3c31ceff5fd5ad751befe211ed5c81b7e8b8f0837e4bad993399dcfdabe639edffabf70b756dcbfcef69db5c04aa54ad0be679d93dab7bb9973fbe6eacfe37f8e1e91bb5f7f3576efd9fe42e7bb2d7547a7fd6723cc2f6abe5d3ea7b6f7fefde2b576602e3535bd69c9be6d5e631c8feddec92edcd7001dea6a9fb263526ef7f6d9779e07",
difficulty: "0x2450fb34e3ea2a",
number: "0xce1986",
gas_limit: "0x1caa0e3",
gas_used: "0x1ca5d1c",
timestamp: "0x617ad6f1",
extra_data: "0x486976656f6e20686b",
mix_hash: "0xe9baa71cbaa92d9d417dd083473fc658b2f6ad0e32f2598c4f46353d64869354",
nonce: "0x97b7dbe2862da2df"
},
future_validator_info: {
block_height:22460216,
wallet_id:"0x295e26495cef6f69dfa69911d9d8e4f3bbadb89b",
accessible:true
},
......
future_validator_info: {
block_height:22460217,
wallet_id:"0x2d4c407bbe49438ed859fe965b140dcf1aab71a9",
accessible:false
},
transaction: {
type: "0x2",
nonce: "0x1714",
gas: "0x206f3",
value: "0x6f05b59d3b200000",
input: "0x52bbbe2900000000000000000000000000000000000000000000000000000000000000e000000000000000000000000013b3a50f3947476eda74fe191344524e2d2d28e5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013b3a50f3947476eda74fe191344524e2d2d28e500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000548139461270ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9212b088d48fc749c5adc573b445bc0d0a289a340002000000000000000000b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000507586012a126421c3669a64b8393fffa9c444620000000000000000000000000000000000000000000000006f05b59d3b20000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000",
v: "0x0",
r: "0xe2261a38f685e318164196727d41c91e497430b3bfd326a71c0bfbec747dcbd6",
s: "0x2d9e98d07f053c4a5ea56ee1a1af3f7fb81bc22bcbb152fd847af12ff5e54bfa",
to: "0xba12222222228d8ba445958a75a0704d566bf2c8",
from: "0x13b3a50f3947476eda74fe191344524e2d2d28e5",
gas_price: null,
hash: "0xf83aa79d4dd6f28bc127b12caf891f61e2e8fdc0b900211dd9c3dcae187fdf37",
chain_id: "0x1",
access_list: [
],
max_fee_per_gas: "0x38e3aebfe4",
max_priority_fee_per_gas: "0x6ccc91d0"
},
......
transaction: {
type: "0x2",
nonce: "0x2e8",
gas: "0x5208",
value: "0xbced73479b86000",
input: "0x",
v: "0x0",
r: "0x46d725064ee3fac9bbb3df1bde7d419b9adc9b1204338df91938d742aa11d1ba",
s: "0x68b7f00d0dcb65153db2af9d1458dc82a8deb65c0b2a52e11b46d8657600d9f6",
to: "0x664cbf2a5b1bc7a9c153ae12f6ba7cefa4d1a482",
from: "0x5907f6596de3235d9a1ddcf4e23535257e88d592",
gas_price: null,
hash: "0xf131d507635a87a89d410f053ac83d18979b2c24106f322ac5285f67ebf05c30",
chain_id: "0x1",
access_list:[
address:"0x18a...998"
storage_keys:"0x43c...a8b"
...
storage_keys:"0x000...136"]
max_fee_per_gas: "0x41a7d25afc",
max_priority_fee_per_gas: "0x68fdbaca"
}