# Parsed Flashblocks

`GetParsedBdnFlashBlockStream` feed provides low-latency access to newly produced Flashblocks on the Base network, parsed into protobuf format for immediate use.\
Flashblocks are pre-confirmation blocks available before they are finalized on-chain and may differ from the final canonical chain.

This is real-time WS/gRPC, parsed Flashblocks data stream.

**Service available via Cloud API only.**

## Stream Endpoint

* Method: `GetParsedBdnFlashBlockStream`
* Endpoint: `wss://base.blxrbdn.com:5005/ws`

### Examples

**Request**

{% tabs %}
{% tab title="WebSocket" %}

```shellscript
wscat -H "Authorization: <AUTH_HEADER>" \
  -c wss://base.blxrbdn.com:5005/ws \
  --wait 1000 \
  --execute '{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": [  "GetParsedBdnFlashBlockStream", {} ]}'
```

{% endtab %}

{% tab title="gRPC" %}

```shellscript
grpcurl -H "Authorization: <AUTH_HEADER>" \
  -H "Content-Type: application/grpc" \
  -d '{}' \
  base.blxrbdn.com:443 \
  streamerapi.Api/GetParsedBdnFlashBlockStream
```

{% endtab %}

{% tab title="Golang" %}

```go
package main

import (
	"encoding/json"
	"net/http"
	"net/url"

	streamerapi "github.com/bloXroute-Labs/base-streamer-proto/streamer_api"
	"github.com/gorilla/websocket"
	"github.com/rs/zerolog/log"
	"google.golang.org/protobuf/encoding/protojson"
)

const (
	BxAuthHeader = "PUT_YOUR_AUTH_HEADER"
)

type Params struct {
	Subscription string          `json:"subscription"`
	Result       json.RawMessage `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()

	message := []byte(`{"jsonrpc": "2.0", "id": 1, "method": "subscribe", "params": [ "GetParsedBdnFlashBlockStream", {} ]}`)
	err = conn.WriteMessage(websocket.TextMessage, message)
	if err != nil {
		log.Fatal().Err(err).Msg("Error sending message: ")
	}

	log.Info().Msg("Connected! Listening for parsed bdn 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 == nil { // Expected for the first update
			log.Warn().Msg("parsedBdnFlashBlock is nil")
			continue
		}

		var parsedBdnFlashBlock streamerapi.GetParsedBdnFlashBlockStreamResponse
		err = protojson.Unmarshal(response.Params.Result, &parsedBdnFlashBlock)
		if err != nil {
			log.Error().Err(err).Msg("Failed to protojson unmarshal parsed bdn flashblock: ")
			continue
		}

		log.Info().Uint64("blockNumber", parsedBdnFlashBlock.Metadata.BlockNumber).Uint64("index", parsedBdnFlashBlock.Index).Msg("parsedBdnFlashBlock")
	}
}
```

{% endtab %}
{% endtabs %}

### Response (Flashblock Event)

* **Index 0 (with Base):** Shows the Flashblock plus chain-level context (`base`).
* **Index 1–10 (without Base):** Shows Flashblocks without repeating that extra context.

{% tabs %}
{% tab title="Index 0 (with Base)" %}

```json
<<< {
    "jsonrpc": "2.0",
    "method": "subscribe",
    "params": {
        "subscription": "37cf3ac8-0c42-4de3-a846-93a57ac94192",
        "result": {
            "payloadId": "0x03272df0619d2be6",
            "index": "0",
            "base": {
                "parentBeaconBlockRoot": "0x18e999429d02c29d269f6bbb0582c44d89b3a7780566326d7f751b2b80cac47d",
                "parentHash": "0xca8312d76b76b1a7c8991726f58c24295753012992bb0441bf7851bd5b37963a",
                "feeRecipient": "0x4200000000000000000000000000000000000011",
                "prevRandao": "0x40f3b694983ecb78f706b5a3a7c8b3a44131751ee1b83d5c78109640ef1cf29d",
                "blockNumber": "0x292e37e",
                "gasLimit": "0x165a0bc0",
                "timestamp": "0x69b023df",
                "extraData": "0x010000007d0000000600000000004c4b40",
                "baseFeePerGas": "0x1a9ec2e"
            },
            "diff": {
                "stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "receiptsRoot": "0x9ab33608eaedfbd6777eeaac90ccef8e418fa17186cc3c4ccd007108c830a73b",
                "logsBloom": "0x00000000...",
                "gasUsed": "0xb48a",
                "blockHash": "0x0196aa157b9bd34cf62267190902e82a53a049688094b81309b94bbe01cb6f5a",
                "transactions": [
                    "0x7ef90106a0f4..."
                ],
                "withdrawals": [],
                "withdrawalsRoot": "0x59b8ad53c839a066fe3def07c96160ed622eadb469c61bf7de0e5d9938f406ad",
                "blobGasUsed": "0x0"
            },
            "metadata": {
                "blockNumber": "43180926",
                "newAccountBalances": {
                    "0x0000f90827f1c53a10cb7a02335b175320002935": "0x0",
                    "0x000f3df6d732807ef1319fb7b8bb8522d0beac02": "0x0",
                    "0x4200000000000000000000000000000000000015": "0x0",
                    "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001": "0x6940facfde7aa"
                },
                "receipts": {
                    "0x1e8d6e55ef7cf8d2dae3c90b853033612fb2faaf0a67a23884f2b21db8361a3b": {
                        "cumulativeGasUsed": "0xb48a",
                        "logs": [],
                        "status": "0x1",
                        "type": "0x7e",
                        "depositNonce": "0x292e381",
                        "depositReceiptVersion": "0x1"
                    }
                }
            }
        }
    }
}
```

{% endtab %}

{% tab title="Index 1-10 (without Base)" %}

```json
<<< {
    "jsonrpc": "2.0",
    "method": "subscribe",
    "params": {
        "subscription": "99908ef9-866d-46b4-8879-845b21ce7e40",
        "result": {
            "payloadId": "0x032bd028914eb14a",
            "index": "1",
            "base": null,
            "diff": {
                "stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "receiptsRoot": "0x7f7709a14a4df083ec46ee667b715056a3865dc341f12a83a0805192b8498a73",
                "logsBloom": "0x40010012482320000...",
                "gasUsed": "0x7826a8",
                "blockHash": "0x6585a097d68710d5b3bc96ad7d89cbd8b06ce7805350fb1f55eb0c670f219d0c",
                "transactions": [
                    "0x02f901f98221058305...",
                    "0x02f901048221058306..."
                    ...
                ],
                "withdrawals": [],
                "withdrawalsRoot": "0x59b8ad53c839a066fe3def07c96160ed622eadb469c61bf7de0e5d9938f406ad",
                "blobGasUsed": "0x11ddf8"
            },
            "metadata": {
                "blockNumber": "43181485",
                "newAccountBalances": {
                    "0x0000000071727de22e5e9d8baf0edac6f37da032": "0x3326df226c1989c82",
                    "0x0000f90827f1c53a10cb7a02335b175320002935": "0x0"
                    ...
                },
                "receipts": {
                    "0x4fda357227d3c56fa97a4c4c446d50ef4468a3c9dde118a0587485a077ca2b49": {
                        "cumulativeGasUsed": "0x6720d",
                        "logs": [],
                        "status": "0x0",
                        "type": "0x0",
                        "depositNonce": "",
                        "depositReceiptVersion": ""
                    },
                    "0x5155ca3e872a57acaf132e84ecd93868d765bc1a31e24435881c42b2f36341fe": {
                        "cumulativeGasUsed": "0x383840",
                        "logs": [],
                        "status": "0x0",
                        "type": "0x1",
                        "depositNonce": "",
                        "depositReceiptVersion": ""
                    },
                    "0xa2f75e1c45eb0247c0a3fe1c6b44dd81c67d3ec4dd54ef0c306b5ae13e2ab621": {
                        "cumulativeGasUsed": "0x3bce1c",
                        "logs": [
                            {
                                "address": "0x0fbbbd928ea4eddd2eaff51d4d412a3b65452f40",
                                "data": "0x000000000000000000000000000000000000000000000000000000000000012c000000000000000000000000000000000000000000000000000000000000000f",
                                "topics": [
                                    "0xdacbdde355ba930696a362ea6738feb9f8bd52dfb3d81947558fd3217e23e325",
                                    "0x0000000000000000000000005fb4a209e02ff14d79f6f65a8f8d4bb7babf4b35"
                                ]
                            }
                        ],
                        "status": "0x1",
                        "type": "0x2",
                        "depositNonce": "",
                        "depositReceiptVersion": ""
                    }
                }
            }
        }
    }
}
```

{% endtab %}
{% endtabs %}
