Get FlashBlockStream
Introduction
This method is used to retrieve FlashBlock data from Base, supporting both gRPC and WebSocket protocols.
Flashblocks are "sub-blocks" streamed on Base every 200 milliseconds, enabling transaction pre-confirmation 10 times faster than the standard 2-second block time. These sub-blocks, called Flashblocks, contain approximately 10% of a full block's transaction data, allowing applications to receive near-instant transaction feedback, suitable for low-latency scenarios.
Endpoint
Region
Endpoint
Frankfurt
frankfurt.grpc.base.blockrazor.xyz:443
Virginia
virginia.grpc.base.blockrazor.xyz:443
Tokyo
tokyo.grpc.base.blockrazor.xyz:443
Rate Limit
Tier 4
Tier 3
Tier 2
Tier 1
Tier 0
FlashBlockStream
-
-
-
✅
✅
Request Example
Access the example here
// GetFlashBlockStream provides a simplified example of subscribing to and processing the flash block stream.
// Note: This function attempts to connect and subscribe only once. For production use, implement your own reconnection logic.
func GetFlashBlockStream(authToken string) {
log.Printf("[FlashStream] Attempting to connect to gRPC server at %s...", grpcAddr)
// Establish a connection to the gRPC server with a timeout.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
conn, err := grpc.DialContext(ctx, grpcAddr,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
)
if err != nil {
log.Printf("[FlashStream] Failed to connect to gRPC server: %v", err)
return
}
defer conn.Close()
log.Println("[FlashStream] Successfully connected to gRPC server.")
client := basepb.NewBaseApiClient(conn)
// Create a new context with authentication metadata for the stream subscription.
streamCtx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs("authorization", authToken))
stream, err := client.GetRawFlashBlockStream(streamCtx, &basepb.GetRawFlashBlocksStreamRequest{})
if err != nil {
log.Printf("[FlashStream] Failed to subscribe to stream: %v", err)
return
}
log.Println("[FlashStream] Subscription successful. Waiting for new flash blocks...")
// Loop indefinitely to receive messages from the stream.
for {
block, err := stream.Recv()
if err != nil {
if err == io.EOF {
log.Println("[FlashStream] Stream closed by the server (EOF).")
} else {
log.Printf("[FlashStream] An error occurred while receiving data: %v", err)
}
break // Exit the loop on error or stream closure.
}
// Process the received flash block data.
jsonString, err := ParseFlashBlockByte(block.Message)
if err != nil {
log.Printf("[FlashStream] Failed to parse flash block data: %v", err)
continue
}
var jsonMap map[string]interface{}
if err := json.Unmarshal([]byte(jsonString), &jsonMap); err != nil {
log.Printf("[FlashStream] Failed to unmarshal flash block JSON: %v", err)
continue
}
printPretty(jsonMap)
}
}
syntax = "proto3";
option go_package = "./basepb";
import "google/protobuf/wrappers.proto";
message BaseBlock {
string parent_hash = 1;
string fee_recipient = 2;
bytes state_root = 3;
bytes receipts_root = 4;
bytes logs_bloom = 5;
bytes prev_randao = 6;
uint64 block_number = 7;
uint64 gas_limit = 8;
uint64 gas_used = 9;
uint64 timestamp = 10;
bytes extra_data = 11;
repeated uint64 base_fee_per_gas = 12;
string block_hash = 13;
repeated bytes transactions = 14;
repeated Withdrawal withdrawals = 15;
google.protobuf.UInt64Value blob_gas_used = 16;
google.protobuf.UInt64Value excess_blob_gas = 17;
google.protobuf.BytesValue withdrawals_root = 18;
}
message Withdrawal {
uint64 index = 1;
uint64 validator = 2;
bytes address = 3;
uint64 amount = 4;
}
message GetRawFlashBlocksStreamRequest {
}
message GetBlockStreamRequest {
}
message SendTransactionRequest {
string rawTransaction = 1;
}
message SendTransactionResponse {
string txHash = 1;
}
message FlashBlockStrRequest {
}
message RawFlashBlockStrResponse {
bytes message = 1;
}
service BaseApi {
rpc SendTransaction(SendTransactionRequest) returns (SendTransactionResponse);
rpc GetBlockStream(GetBlockStreamRequest) returns (stream BaseBlock);
rpc GetRawFlashBlockStream(GetRawFlashBlocksStreamRequest) returns (stream RawFlashBlockStrResponse);
}
Response
Normal
{
message: "185329……7e04b7"
}
Abnormal
rpc error: code = Unknown desc = Authentication information is missing. Please provide a valid auth token
Last updated