txReceipts
Only available on Go and Python Gateways.
Name: txReceipts
txReceipts is a stream of all transaction receipts in each newly mined block.
Gateway must have a local node connection as well as be using the eth-ws-uristartup argument.
Options
Note - If using Python Gateway values must be prefixed with receipt.
i.e receipt.block_hash .
Key
Description
Values
include
Fields to include in the receipts stream
block_hash, block_number, contract_address, cumulative_gas_used, from, gas_used, logs, logs_bloom, status, to, transaction_hash, transaction_index [Default: all]
​
Code Examples
wscat
Node.js
Python
Golang
1
wscat -c ws://127.0.0.1:28333/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
2
> {"id": 1, "method": "subscribe", "params": ["txReceipts", {"include": []}]}
3
< ......
4
​
Copied!
1
var fs = require('fs');
2
const WebSocket = require('ws');
3
​
4
const ws = new WebSocket(
5
"ws://127.0.0.1:28333/ws",
6
{
7
headers: {
8
"Authorization" : <YOUR-AUTHORIZATION-HEADER>
9
},
10
rejectUnauthorized: false,
11
}
12
);
13
​
14
function proceed() {
15
ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": ["txReceipts", {"include": []}]}`);
16
}
17
​
18
​
19
function handle(nextNotification) {
20
console.log(nextNotification.toString()); // or process it generally
21
}
22
​
23
ws.on('open', proceed);
24
ws.on('message', handle);
Copied!
Go Gateway
1
import asyncio
2
from bxcommon.rpc.provider.ws_provider import WsProvider
3
async def main():
4
async with WsProvider(
5
uri="ws://127.0.0.1:28333/ws",
6
headers={"Authorization": <YOUR-AUTHORIZATION-HEADER>}
7
) as ws:
8
subscription_id = await ws.subscribe("txReceipts", {"include": []})
9
while True:
10
next_notification = await ws.get_next_subscription_notification_by_id(subscription_id)
11
print(next_notification) # or process it generally
12
await ws.unsubscribe(subscription_id)
13
if __name__ == '__main__':
14
asyncio.get_event_loop().run_until_complete(main())
Copied!
Python Gateway
1
import asyncio
2
from bxcommon.rpc.provider.ws_provider import WsProvider
3
ws_uri = "ws://127.0.0.1:28333"
4
async def main():
5
async with WsProvider(ws_uri) as ws:
6
subscription_id = await ws.subscribe("txReceipts", {"include": ["receipt"]})
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
await ws.unsubscribe(subscription_id)
11
if __name__ == '__main__':
12
asyncio.get_event_loop().run_until_complete(main())
Copied!
1
package main
2
​
3
import (
4
"crypto/tls"
5
"fmt"
6
"net/http"
7
"github.com/gorilla/websocket"
8
)
9
​
10
func main() {
11
tlsConfig := &tls.Config{
12
InsecureSkipVerify: true,
13
}
14
dialer := websocket.DefaultDialer
15
dialer.TLSClientConfig = tlsConfig
16
wsSubscriber, _, err := dialer.Dial("ws://127.0.0.1:28333/ws", http.Header{"Authorization": []string{<YOUR-AUTHORIZATION-HEADER>}})
17
​
18
if err != nil {
19
fmt.Println(err)
20
return
21
}
22
​
23
subRequest := `{"id": 1, "method": "subscribe", "params": ["txReceipts", {"include": []}]}`
24
err = wsSubscriber.WriteMessage(websocket.TextMessage, []byte(subRequest))
25
if err != nil {
26
fmt.Println(err)
27
return
28
}
29
​
30
for {
31
_, nextNotification, err := wsSubscriber.ReadMessage()
32
if err != nil {
33
fmt.Println(err)
34
}
35
fmt.Println(string(nextNotification)) // or process it generally
36
}
37
}
38
​
Copied!
​
Response Example
Transaction Receipt Event
1
<<< {"jsonrpc": "2.0", "id": null,
2
"result": {"blockHash":"0x1580cb....c950122b837",
3
"blockNumber":"0xb128cc",
4
"contractAddress":null,
5
"cumulativeGasUsed":"0x4e1fb7",
6
"from":"0x80bb1...7bf44058a48a",
7
"gasUsed":"0x1d918",
8
"logs":[{"address":"0x68caa...87846652822ae4b5",
9
"topics":["0x3ae9ad...c40b5a","0x000000000...058a48a"],
10
"data":"0x0000...f3784",
11
"blockNumber":"0xb128cc",
12
"transactionHash":"0x12316c...3080bc012",
13
"transactionIndex":"0x4b",
14
"blockHash":"0x1580cb8419...22b837",
15
"logIndex":"0x7a",
16
"removed":false}],
17
"logsBloom":"0x00000...0000",
18
"status":"0x1",
19
"to":"0x68ca...22ae4b5",
20
"transactionHash":"0x12316...0bc012",
21
"transactionIndex":"0x4b",
22
"type":"0x0"}}
Copied!
Copy link