Flashblocks Statediff
GetBdnFBTxnStateDiffStream feed provides low-latency access to transaction state diffs for newly produced Flashblocks on the Base network, parsed into protobuf format for immediate use. Transaction state diffs show the changes each transaction makes to chain state before finalization.
This is a real-time WS/gRPC, transaction state diff data stream.
Service available via Cloud API only.
Stream Endpoint
Method:
GetBdnFBTxnStateDiffStreamEndpoint:
wss://base.blxrbdn.com:5005/ws
Parameters
addresses
Stream transaction traces that mention one of these addresses
[Optional] List of strings. If omitted, the stream includes state diffs of all transactions.
include_logs
Include logs emitted during transaction execution
[Optional] Boolean. If true, logs will be included with each state diff update.
Examples
Request
wscat -H "Authorization: <AUTH_HEADER>" \
-c wss://base.blxrbdn.com:5005/ws \
--wait 1000 \
--execute '{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": [ "GetBdnFBTxnStateDiffStream", {"include_logs": true} ]}'grpcurl -H "Authorization: <AUTH_HEADER>" \
-H "Content-Type: application/grpc" \
-d '{"addresses":["0x4200000000000000000000000000000000000006"]}' \
base.blxrbdn.com:443 \
streamerapi.Api/GetBdnFBTxnStateDiffStreampackage main
import (
"context"
"fmt"
"time"
"github.com/bloXroute-Labs/base-streamer-client-go/provider"
streamerapi "github.com/bloXroute-Labs/base-streamer-proto/streamer_api"
"github.com/joho/godotenv"
)
func main() {
_ = godotenv.Load() // Set you AUTH_HEADER in .env file
err := ListenForBdnFBTxnStateDiffStream(10)
if err != nil {
panic(err)
}
}
func ListenForBdnFBTxnStateDiffStream(numberOfBlocks uint64) error {
grpcClient, err := provider.NewGRPCClient()
if err != nil {
return err
}
stateDiffsChan := make(chan *streamerapi.GetBdnFBTxnStateDiffStreamResponse)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
stream, err := grpcClient.GetBdnFBTxnStateDiffStream(ctx, nil) // Optionally filter by mentioned addresses
if err != nil {
return fmt.Errorf("failed to get stream with: %v", err)
}
stream.Into(stateDiffsChan)
fmt.Println("waiting on state diffs channel")
for range numberOfBlocks {
stateDiff, ok := <-stateDiffsChan
if !ok {
return fmt.Errorf("state diffs channel closed")
}
updateTime := time.Now()
// Display to user
fmt.Printf("Bloxroute BDN Flashblock txn state diff at %v: block_number: %v, block_position: %v, flashblock_index: %v, tx_hash: %v, is_success: %v\n",
updateTime.UTC(), *stateDiff.BlockNumber, *stateDiff.BlockPosition, *stateDiff.FlashblockIndex, *stateDiff.TxHash, *stateDiff.IsSuccess)
for k, v := range stateDiff.Trace.Pre {
balance := ""
if v.Balance != nil {
balance = *v.Balance
}
fmt.Printf("pre: %s: balance: %s, storage: %+v\n", k, balance, v.Storage)
}
fmt.Println("")
for k, v := range stateDiff.Trace.Post {
balance := ""
if v.Balance != nil {
balance = *v.Balance
}
fmt.Printf("post: %s: balance: %s, storage: %+v\n", k, balance, v.Storage)
}
fmt.Println("----------------------")
}
return nil
}Response (txn state diff)
Full response details & format can be found here: https://github.com/bloXroute-Labs/base-streamer-proto/blob/develop/proto/streamer_api.proto
Last updated