GetBdnFlashBlockStream
Name: GetBdnFlashBlockStream
The GetBdnFlashBlockStream
stream provides low-latency access to newly produced Flashblocks on the Base network. Flashblocks are pre-confirmation blocks available before they are finalized on-chain and may differ from the final canonical chain.
This is a real-time WS/gRPC, raw Flashblocks data stream.
Example: WebSocket using CLI
wscat -H "Authorization: <AUTH_HEADER>" \
-c wss://base.blxrbdn.com:5005/ws \
--wait 1000 \
--execute '{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": [ "GetBdnFlashBlockStream", {} ]}'
Example: Test with grpcurl
grpcurl -H "Authorization: <AUTH_HEADER>" \
-H "Content-Type: application/grpc" \
-d '{}' \
base.blxrbdn.com:443 \
streamerapi.Api/GetBdnFlashBlockStream
Example: Golang
package main
import (
"encoding/json"
"net/http"
"net/url"
"github.com/gorilla/websocket"
"github.com/rs/zerolog/log"
)
const (
BxAuthHeader = "PUT_YOUR_AUTH_HEADER"
)
type Result struct {
BdnFlashBlock []byte `json:"bdnFlashBlock"`
}
type Params struct {
Subscription string `json:"subscription"`
Result Result `json:"result"`
}
type Response struct {
JsonRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params Params `json:"params"`
}
func main() {
u, err := url.Parse("wss://base.blxrbdn.com:5005/ws")
if err != nil {
log.Fatal().Err(err).Msg("Invalid WebSocket URL: ")
}
log.Info().Str("url", u.String()).Msg("Connecting...")
conn, _, err := websocket.DefaultDialer.Dial(u.String(), http.Header{
"Authorization": []string{BxAuthHeader},
})
if err != nil {
log.Fatal().Err(err).Msg("WebSocket connection failed: ")
}
defer conn.Close()
request := []byte(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": [ "GetBdnFlashBlockStream", {} ]}`)
err = conn.WriteMessage(websocket.TextMessage, request)
if err != nil {
log.Fatal().Err(err).Msg("Error sending message: ")
}
log.Info().Msg("Connected! Listening for Flashblocks...")
for {
msgType, msg, err := conn.ReadMessage()
if err != nil {
log.Error().Err(err).Msg("Read error: ")
continue
}
if msgType != websocket.TextMessage {
log.Error().Err(err).Int("msgType", msgType).Msg("Skipping non-text message: ")
continue
}
var response *Response
err = json.Unmarshal(msg, &response)
if err != nil {
log.Error().Err(err).Msg("Failed to unmarshal response: ")
continue
}
if response.Params.Result.BdnFlashBlock == nil { // Expected for the first update
log.Warn().Msg("BdnFlashBlock is nil")
continue
}
// Use the Brotli-compressed Flashblock...
log.Info().Msg("Got Flashblock")
}
}
Last updated