newBlocks
Available on Python Gateway, Go-Gateway and Cloud API
Note: Users planning to use this stream with Go-Gateway should ensure they have a local node ws connection.
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,uncles
[Default: all]

Examples (Cloud-API)

wscat
Python
Node.js
Golang
1
## ETH Example
2
wscat -c wss://virginia.eth.blxrbdn.com/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
3
> {"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"]}]}
4
< ......
5
​
6
​
7
## BSC Example
8
wscat -c wss://virginia.bsc.blxrbdn.com/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
9
> {"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"}]}
10
< ......
11
​
12
​
13
## Polygon Example
14
wscat -c wss://virginia.polygon.blxrbdn.com/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
15
> {"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "Polygon-Mainnet"}]}
16
< ......
17
​
Copied!
1
from bxcommon.rpc.provider.ws_provider import WsProvider
2
​
3
# Enterprise users can follow line 4-9 to
4
async with WsProvider(
5
uri="wss://virginia.eth.blxrbdn.com/ws",
6
headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>},
7
# Add the following line if you work with IP instead of DNS
8
# skip_ssl_cert_verify=True
9
) as ws:
10
​
11
# Non Enterprise users should follow line 12-17
12
# async with WsProvider(
13
# uri="wss://api.blxrbdn.com/ws",
14
# headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>}
15
# Add the following line if you work with IP instead of DNS
16
# skip_ssl_cert_verify=True
17
# ) as ws:
18
​
19
# ETH Example
20
subscription_id = await ws.subscribe("newBlocks", {"include": ["tx_hash"]})
21
​
22
# BSC Example (only available at endpoint wss://<region>.bsc.blxrbdn.com/ws)
23
# subscription_id = await ws.subscribe("newBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"})
24
​
25
# Polygon Example (only available at endpoint wss://<region>.polygon.blxrbdn.com/ws)
26
# subscription_id = await ws.subscribe("newBlocks", {"include": ["hash"], "blockchain_network": "Polygon-Mainnet"})
27
​
28
while True:
29
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
30
print(next_notification) # or process it generally
31
await ws.unsubscribe(subscription_id)
Copied!
1
var fs = require('fs');
2
const WebSocket = require('ws');
3
​
4
// Enterprise users can follow line 5-16
5
const ws = new WebSocket(
6
'wss://virginia.eth.blxrbdn.com/ws', // for ETH
7
// use 'wss://virginia.bsc.blxrbdn.com/ws', //for BSC
8
// use 'wss://virginia.polygon.blxrbdn.com/ws', // for Polygon
9
{
10
headers: {
11
"Authorization" : <YOUR-AUTHORIZATION-HEADER>
12
},
13
// Add the following line if you work with IP instead of DNS
14
// rejectUnauthorized: false,
15
}
16
);
17
​
18
// Non Enterprise users should follow line 19-27
19
// const ws = new WebSocket(
20
// "wss://api.blxrbdn.com/ws",
21
// {
22
// headers: {
23
// "Authorization" : <YOUR-AUTHORIZATION-HEADER>
24
// },
25
// rejectUnauthorized: false,
26
// }
27
// );
28
​
29
function proceed() {
30
// ETH Example
31
ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["tx_hash"]}]}`);
32
​
33
// BSC Example (only available at endpoint wss://<region>.bsc.blxrbdn.com/ws)
34
// ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"}]}`);
35
​
36
// Polygon Example (only available at endpoint wss://<region>.polygon.blxrbdn.com/ws)
37
// ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "Polygon-Mainnet"}]}`);
38
}
39
​
40
​
41
function handle(nextNotification) {
42
console.log(nextNotification.toString()); // or process it generally
43
}
44
​
45
ws.on('open', proceed);
46
ws.on('message', handle);
Copied!
1
package main
2
​
3
import (
4
"crypto/tls"
5
"fmt"
6
"github.com/gorilla/websocket"
7
"net/http"
8
)
9
​
10
func main() {
11
dialer := websocket.DefaultDialer
12
// Add the following lines if you work with IP instead of DNS
13
// tlsConfig := &tls.Config{
14
// Certificates: []tls.Certificate{cert},
15
// InsecureSkipVerify: true,
16
// }
17
// dialer.TLSClientConfig = tlsConfig
18
​
19
// Enterprise users can follow line 20
20
wsSubscriber, _, err := dialer.Dial("wss://virginia.eth.blxrbdn.com/ws", http.Header{"Authorization": []string{<YOUR-AUTHORIZATION-HEADER>}})
21
​
22
// Non Enterprise users can follow line 23
23
// wsSubscriber, _, err := dialer.Dial("wss://api.blxrbdn.com/ws", http.Header{"Authorization": []string{<YOUR-AUTHORIZATION-HEADER>}})
24
​
25
if err != nil {
26
fmt.Println(err)
27
return
28
}
29
​
30
// ETH Example
31
subRequest := `{"id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"]}]}`
32
​
33
// BSC Example (only available at endpoint wss://<region>.bsc.feed.blxrbdn.com:28333)
34
// subRequest := `{"id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "BSC-Mainnet"}]}`
35
​
36
// Polygon Example (only available at endpoint wss://<region>.polygon.blxrbdn.com:28333)
37
// subRequest := `{"id": 1, "method": "subscribe", "params": ["newBlocks", {"include": ["hash"], "blockchain_network": "Polygon-Mainnet"}]}`
38
​
39
err = wsSubscriber.WriteMessage(websocket.TextMessage, []byte(subRequest))
40
if err != nil {
41
fmt.Println(err)
42
return
43
}
44
​
45
for {
46
_, nextNotification, err := wsSubscriber.ReadMessage()
47
if err != nil {
48
fmt.Println(err)
49
}
50
fmt.Println(string(nextNotification)) // or process it generally
51
}
52
}
53
​
Copied!

Response (Block Event)

Block Event
1
<<< {"jsonrpc": "2.0", "id": null, "method": "subscribe",
2
"params": {"subscription": "213883fe-b3e2-4da2-b9ba-196a82df8628",
3
"result": {"hash": "0x079b7f1b5a68d4301cf97df2f81c406aa598dd508e2d1908974b95ddd61a4156",
4
"header": {"parentHash": "0xafef6c6bd1049febe85834aa84735f81f2e81efd55d85a1076aae0adceba16de",
5
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
6
"miner": "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
7
"stateRoot": "0x13f4a37eb7d0ca8ea309a631e51cca86eaa1b9765a2e6a9eb1614ddcf4ea57e4",
8
"transactionsRoot": "0x33d0f3c1ce4e3be6346738465cafc727f3500990c881d6fe4821567504badfd5",
9
"receiptsRoot": "0xad4fe2b36823a0b57f1c640d115eacc8cc1e64c73e49f89a131f206457afbf9f",
10
"logsBloom": "0x3862455e6027e5863992de359e89bd33e91312891441903f715503c922420904c00e77b054483930423b7a0b5aa4433342b5c096fb3a0883a970d882b9ac02104582cab5eb046e62c9ca17acba8268e25c103107216cec48bc432d78b54927991c5147080a5781c028102040a28ab8d016439e6f8a4804b44c15c3fa85873c204ab8938d450f702ec2444f5a83028586683439ff6de3e57be46c295514527dbcc717f08804c1ac022fcccac7c058d447122e109294a38c3b1a2a676c9814c6913200414e638eb046ed244035875a0c2e446132bd450223952a9bbcd694666884a03db1340b8010dfaae464948a9b4ae524ff8a942258445c73ce176bee981b7d",
11
"difficulty": "0xc39780fb04af3",
12
"number": "0xab05c3",
13
"gasLimit": "0xbdfca5",
14
"gasUsed": "0xbdb8e3",
15
"timestamp": "0x5fa62290",
16
"extraData": "0x65746865726d696e652d6575312d36",
17
"mixHash": "0x3cd96f6536c1cc745ce9a4f767d65a94b64392bc787e029e7c16339641265b0a",
18
"nonce": "0x327b58b8b7216cf5"},
19
"transactions": [{"from": "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
20
"gas": "0xc350",
21
"gasPrice": "0x3b9aca00",
22
"hash": "0x587a2db59d1af16aa03521a711c3db5b443e5d05cfc72eccadb89c99380f7da0",
23
"input": "0x",
24
"nonce": "0x1b8a09b",
25
"value": "0x54fbe53cd2d1338",
26
"v": "0x25",
27
"r": "0x41f3261e25a3e77abd4b0bd4f21cfc2d92ca2d52ff9c663c9a68c6a382115dac",
28
"s": "0x4350bb6f770bb3363094774fe36478b20013c705f4041fc1bcd0f9fe520c9a23",
29
"to": "0x190aab185dbf089b1c5cf06a4f13421c14fc18fa"},
30
...
31
{"from": "0xc88f7666330b4b511358b7742dc2a3234710e7b1",
32
"gas": "0x5208",
33
"gasPrice": "0x7aef40a00",
34
"hash": "0x92df6598e3a2bc9550898fd7b3322594228e513c0098333bbefd6784a1aa90db",
35
"input": "0x",
36
"nonce": "0x6827c",
37
"value": "0x36e9c396c89e000",
38
"v": "0x25",
39
"r": "0x1653aae7a09b85b923b4602f69886c816f470f9b5167d16f2cbb963d00345583",
40
"s": "0x2c429419c8f23172d4fe4177f796daacf6cfccd9d1545d62957e13fa4af933db",
41
"to": "0x844359bf8d5fa20f32b0d679527adb93d6255abf"}],
42
"uncles": []}}}
Copied!
Copy link
Contents