newTxs and pendingTxs
Name: newTxs , pendingTxs

Options

Key
Description
Values
include
Fields to include in the transaction stream. The subscription plan determines the list of available fields.
tx_hash,tx_contents[Default: all]
duplicates
Whether or not to include transactions
already published in the feed.
True,False[Default]
include_from_blockchain
Whether or not to include transactions received first from the connected blockchain node. (Mainly used for testing)
True[Default],False
filters
You can specify filters in SQL-Like format to only receive certain transactions.
Users can customize the filters.
blockchain_network
Blockchain network name. Use with Cloud-API when working with BSC
Mainnet [Default, Ethereum Mainnet], BSC-Mainnet
The BDN supports subscribing to two transaction streams:
    1.
    newTxs is a stream of all new transactions as they are propagated in the BDN.
    2.
    pendingTxs is a stream of all new transactions as they enter the Ethereum/BSC transaction pool.
For expedience, all transactions received through the BDN are immediately published to the newTxs feed. By design, the Gateway/Cloud-API do not perform the same detail of transaction validation that the Ethereum nodes do, and cannot completely guarantee that all transactions propagated are valid (e.g. the Gateway/Cloud-API do not check for double spends). Therefore, these transactions have had basic validations done (e.g. checksums and other sanity checks) but may not be accepted into the TxPool.
The Gateway/Cloud-API can then leverage the Ethereum nodes for further validation of the transaction (e.g. check that it will be accepted into the TxPool), and publish results to the pendingTxs feed. Users planning to use pendingTxs with a Gateway feed should enable validation against their local Ethereum node.
It is expected that newTxsstream will perform faster than pendingTxs. The performance difference can be significant (10-100ms). Users interested in timely transaction information could find newTxs stream more appealing, while those who rely on strict correctness of the transactions data should utilize the pendingTxsstream.
The newTxs stream can send transactions that have been (a) previously confirmed hours or days prior, or (b) replaced by a higher priced transaction with the same nonce. It is recommended that users with latency sensitive applications track the latest nonce for each account and use it to filter out stale messages.
The fields allowed in the include section depends on the user's subscription plan:
Plan
Available Fields
Introductory
tx_hash
Developer
tx_hash, tx_contents.from, tx_contents.to, tx_contents.value, tx_contents.nonce, tx_contents.gas, tx_contents.gas_price, tx_contents.max_priority_fee_per_gas, tx_contents.max_fee_per_gas
Professional, Enterprise
tx_hash, tx_contents.input, tx_contents.v, tx_contents.r, tx_contents.s, tx_contents.from, tx_contents.to, tx_contents.value, tx_contents.nonce, tx_contents.gas, tx_contents.gas_price ,tx_contents.max_priority_fee_per_gas, tx_contents.max_fee_per_gas
Enterprise Elite - Light Gateway
tx_hash, tx_contents.input, tx_contents.v, tx_contents.r, tx_contents.s, tx_contents.from, tx_contents.to, tx_contents.value, tx_contents.nonce, tx_contents.gas, tx_contents.gas_price , tx_contents.max_priority_fee_per_gas, tx_contents.max_fee_per_gas, raw_tx
The transaction feed will publish the data for each transaction in a separate message. Users that are only interested in a subset of transactions can utilize the feed's filtering options.

Examples

Requests (Cloud-API)

Notes:
    Follow the examples below based on your subscription plan. We suggest you to use "try...catch" to better handle exceptions caused by potential disconnections. The examples below contain the minimum code required for all transactions stream subscriptions.
    Enterprise plan users can choose to work directly with wss://<NETWORK-NAME>.feed.blxrbdn.com:28333(e.g.wss://eth.feed.blxrbdn.com:28333 for ETH)
    for the best performance.
    Non-Enterprise plan users should use wss://api.blxrbdn.com/ws.
    See Cloud-API IPs to work directly with IP ( wss://<IP>/ws)
wscat
Python
Node.js
Golang
1
## ETH Example
2
# Enterprise users can follow line 3-5 to use wss://eth.feed.blxrbdn.com:28333
3
wscat -c wss://eth.feed.blxrbdn.com:28333 --no-check --cert /usr/bloxroute/certificate/external_gateway/registration_only/external_gateway_cert.pem --key /usr/bloxroute/certificate/external_gateway/registration_only/external_gateway_key.pem
4
> {"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]}
5
< ......
6
​
7
# Non Enterprise users should follow line 8-10 to use wss://api.blxrbdn.com/ws
8
# wscat -c wss://api.blxrbdn.com/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
9
# > {"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]}
10
# < ......
11
​
12
​
13
## BSC Example
14
wscat -c wss://bsc.feed.blxrbdn.com:28333 --no-check --cert /usr/bloxroute/certificate/external_gateway/registration_only/external_gateway_cert.pem --key /usr/bloxroute/certificate/external_gateway/registration_only/external_gateway_key.pem
15
> {"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"], "blockchain_network": "BSC-Mainnet"}]}
16
< ......
17
​
18
​
Copied!
1
from bloxroute_cli.provider.cloud_wss_provider import CloudWssProvider
2
​
3
# Enterprise users can follow line 4-7 to use wss://eth.feed.blxrbdn.com:28333 for ETH
4
async with CloudWssProvider(
5
ssl_dir="/usr/bloxroute/certificate/external_gateway/registration_only",
6
ws_uri="wss://eth.feed.blxrbdn.com:28333" # use wss://bsc.feed.blxrbdn.com:28333 for BSC
7
) as ws:
8
​
9
# Non Enterprise users should follow line 10-13 to use wss://api.blxrbdn.com/ws
10
# async with WsProvider(
11
# uri="wss://api.blxrbdn.com/ws",
12
# headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>}
13
# ) as ws:
14
​
15
# ETH Example
16
subscription_id = await ws.subscribe("newTxs", {"include": ["tx_hash"]})
17
# BSC Example (only available at endpoint wss://bsc.feed.blxrbdn.com:28333)
18
# subscription_id = await ws.subscribe("newTxs", {"include": ["tx_hash"], "blockchain_network": "BSC-Mainnet"})
19
​
20
while True:
21
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
22
print(next_notification) # or process it generally
23
await ws.unsubscribe(subscription_id)
24
Copied!
1
var fs = require('fs');
2
const WebSocket = require('ws');
3
​
4
// Enterprise users can follow line 5-12 to use wss://eth.feed.blxrbdn.com:28333 for ETH
5
const ws = new WebSocket(
6
'wss://eth.feed.blxrbdn.com:28333', // use wss://bsc.feed.blxrbdn.com:28333 for BSC
7
{
8
cert: fs.readFileSync('/usr/bloxroute/certificate/external_gateway/registration_only/external_gateway_cert.pem'),
9
key: fs.readFileSync('/usr/bloxroute/certificate/external_gateway/registration_only/external_gateway_key.pem'),
10
rejectUnauthorized: false,
11
}
12
);
13
​
14
// Non Enterprise users should follow line 15-23 to use wss://api.blxrbdn.com/ws
15
// const ws = new WebSocket(
16
// "wss://api.blxrbdn.com/ws",
17
// {
18
// headers: {
19
// "Authorization" : <YOUR-AUTHORIZATION-HEADER>
20
// },
21
// rejectUnauthorized: false,
22
// }
23
// );
24
​
25
function proceed() {
26
// ETH Example
27
ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]}`);
28
// BSC Example (only available at endpoint wss://bsc.feed.blxrbdn.com:28333)
29
// ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"], "blockchain_network": "BSC-Mainnet"}]}`);
30
​
31
}
32
​
33
​
34
function handle(nextNotification) {
35
console.log(nextNotification.toString()); // or process it generally
36
}
37
​
38
ws.on('open', proceed);
39
ws.on('message', handle);
40
​
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
// Enterprise users can follow line 12-27 to use wss://eth.feed.blxrbdn.com:28333 for ETH
12
cert, err := tls.LoadX509KeyPair(
13
"/usr/bloxroute/certificate/external_gateway/registration_only/external_gateway_cert.pem",
14
"/usr/bloxroute/certificate/external_gateway/registration_only/external_gateway_key.pem",
15
)
16
if err != nil {
17
fmt.Println(err)
18
return
19
}
20
​
21
tlsConfig := &tls.Config{
22
Certificates: []tls.Certificate{cert},
23
InsecureSkipVerify: true,
24
}
25
dialer := websocket.DefaultDialer
26
dialer.TLSClientConfig = tlsConfig
27
wsSubscriber, _, err := dialer.Dial("wss://eth.feed.blxrbdn.com:28333", nil) // use wss://bsc.feed.blxrbdn.com:28333 for BSC
28
29
// Non Enterprise users should follow line 30-35 to use wss://api.blxrbdn.com/ws
30
// tlsConfig := &tls.Config{
31
// InsecureSkipVerify: true,
32
// }
33
// dialer := websocket.DefaultDialer
34
// dialer.TLSClientConfig = tlsConfig
35
// wsSubscriber, _, err := dialer.Dial("wss://api.blxrbdn.com/ws", http.Header{"Authorization": []string{<YOUR-AUTHORIZATION-HEADER>}})
36
​
37
if err != nil {
38
fmt.Println(err)
39
return
40
}
41
​
42
// ETH Example
43
subRequest := `{"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]}`
44
// BSC Example (only available at endpoint wss://bsc.feed.blxrbdn.com:28333)
45
// subRequest := `{"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"], "blockchain_network": "BSC-Mainnet"}]}`
46
err = wsSubscriber.WriteMessage(websocket.TextMessage, []byte(subRequest))
47
if err != nil {
48
fmt.Println(err)
49
return
50
}
51
​
52
for {
53
_, nextNotification, err := wsSubscriber.ReadMessage()
54
if err != nil {
55
fmt.Println(err)
56
}
57
fmt.Println(string(nextNotification)) // or process it generally
58
}
59
}
60
​
Copied!

Requests (Gateway-API)

Notes:
    We assume that the Gateway IP is 127.0.0.1 with default ws port 28333 in the examples below.
wscat
Python
Node.js
Golang
1
wscat -c ws://127.0.0.1:28333
2
> {"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]}
3
< ......
4
​
Copied!
1
from bloxroute_cli.provider.ws_provider import WsProvider
2
ws_uri = "ws://127.0.0.1:28333"
3
while True:
4
try:
5
async with WsProvider(ws_uri) as ws:
6
subscription_id = await ws.subscribe("newTxs", {"include": ["tx_hash"]})
7
while True:
8
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
9
print(next_notification) # or process it generally
10
except Exception as e:
11
print(f"Connection broken to feed, {str(e)}, retrying.")
12
await ws.unsubscribe(subscription_id)
13
​
Copied!
1
const WebSocket = require('ws');
2
​
3
const ws = new WebSocket(
4
'ws://127.0.0.1:28333',
5
);
6
​
7
​
8
function proceed() {
9
ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]}`);
10
}
11
​
12
​
13
function handle(nextNotification) {
14
console.log(nextNotification.toString()); // or process it generally
15
}
16
​
17
ws.on('open', proceed);
18
ws.on('message', handle);
19
​
Copied!
1
package main
2
​
3
import (
4
"fmt"
5
"github.com/gorilla/websocket"
6
)
7
​
8
func main() {
9
dialer := websocket.DefaultDialer
10
wsSubscriber, _, err := dialer.Dial("ws://127.0.0.1:28333", nil)
11
12
if err != nil {
13
fmt.Println(err)
14
return
15
}
16
​
17
subRequest := `{"id": 1, "method": "subscribe", "params": ["newTxs", {"include": ["tx_hash"]}]}`
18
err = wsSubscriber.WriteMessage(websocket.TextMessage, []byte(subRequest))
19
if err != nil {
20
fmt.Println(err)
21
return
22
}
23
​
24
for {
25
_, nextNotification, err := wsSubscriber.ReadMessage()
26
if err != nil {
27
fmt.Println(err)
28
}
29
fmt.Println(string(nextNotification)) // or process it generally
30
}
31
}
32
​
Copied!

​

Response (Tx Event)

Transaction Event
1
# Examples for Professional and Enterprise plan:
2
# Type 0 legacy transction:
3
<<< {
4
"jsonrpc":"2.0",
5
"id":null,
6
"method":"subscribe",
7
"params":{
8
"subscription":"414f2873-a7b0-451c-aefa-4e9280f25ce7",
9
"result":{
10
"txHash":"0x277...2ae",
11
"txContents":{
12
"from":"0xcfc...bf2",
13
"gas":"0x8caf",
14
"gasPrice":"0x8d8f9fc00",
15
"hash":"0x277...2ae",
16
"input":"0x2e1...000",
17
"nonce":"0x1eb",
18
"value":"0x0",
19
"v":"0x26",
20
"r":"0xbf7...742",
21
"s":"0x249...346",
22
"type":"0x0",
23
"to":"0xc02...cc2"
24
},
25
"localRegion":true
26
}
27
}
28
}
29
# Type 2 dynamic fee transaction:
30
<<< {
31
"jsonrpc":"2.0",
32
"id":null,
33
"method":"subscribe",
34
"params":{
35
"subscription":"414f2873-a7b0-451c-aefa-4e9280f25ce7",
36
"result":{
37
"txHash":"0x03...da0",
38
"txContents":{
39
"from":"0x001...9e8",
40
"gas":"0xd6d8",
41
"gasPrice":null,
42
"hash":"0x03...da0",
43
"input":"0x",
44
"nonce":"0x2e6c02",
45
"value":"0x8087c960bae00",
46
"v":"0x1",
47
"r":"0xc44...431",
48
"s":"0x4bd...858",
49
"type":"0x2",
50
"to":"0xdea...aac",
51
"chainId":"0x1",
52
"accessList":[],
53
"maxPriorityFeePerGas":"0x3b9aca00",
54
"maxFeePerGas":"0xba43b7400"
55
},
56
"localRegion":true
57
}
58
}
59
}
60
​
Copied!
Last modified 20d ago
Copy link
Contents
Examples