# 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.**

{% hint style="info" %}
Note: state diffs may arrive in a different order than transactions are executed; each response includes a `blockPosition` field for ordering.
{% endhint %}

## Stream Endpoint

* Method: `GetBdnFBTxnStateDiffStream`&#x20;
* Endpoint: `wss://base.blxrbdn.com:5005/ws`

#### Parameters

<table><thead><tr><th width="166.61958821614581">Parameter</th><th width="261.968017578125">Description</th><th width="321.2836100260417">Instructions &#x26; Notes</th></tr></thead><tbody><tr><td><code>addresses</code></td><td>Stream transaction traces that mention one of these addresses</td><td><em>[<strong>Optional</strong>]</em> List of strings. If omitted, the stream includes state diffs of all transactions.</td></tr><tr><td><code>include_logs</code></td><td>Include logs emitted during transaction execution</td><td>[Optional] Boolean. If <code>true</code>, logs will be included with each state diff update.</td></tr></tbody></table>

## 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": [ "GetBdnFBTxnStateDiffStream", {"include_logs": true} ]}'
```

{% endtab %}

{% tab title="gRPC" %}

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

{% endtab %}

{% tab title="Golang" %}

```go
package 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
}
```

{% endtab %}
{% endtabs %}

#### 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>

{% tabs %}
{% tab title="Txns Event" %}

```json
<<< {
  "blockNumber": "45591785",
  "blockPosition": "92",
  "flashblockIndex": "4",
  "txHash": "0x5433823fbec68c5ab060442e5518a0cc4cd878284d350adfdaff15b1fb3acc21",
  "trace": {
    "pre": {
      "0x83620EAb3DC8403C91106fe923A3e9E5926aE3f9": {
        "balance": "0",
        "storage": {
          "0x28410d8a1e329a1b046f643b75d001efbb0ab30b6d59b3924752da4dbb33deff": "0x00000000000000000000000000000000000069f9b66d0069f9b6650000000000"
        }
      }
    },
    "post": {
      "0x83620EAb3DC8403C91106fe923A3e9E5926aE3f9": {
        "storage": {
          "0x28410d8a1e329a1b046f643b75d001efbb0ab30b6d59b3924752da4dbb33deff": "0x00000000000000000000000000000000000069f9b6b50069f9b6ab0000000000"
        }
      }
    }
  },
  "isSuccess": true,
  "logs": [
    {
      "address": "0x83620EAb3DC8403C91106fe923A3e9E5926aE3f9",
      "topics": [
        "0xa42de58202191be32704b9a032c0087d3fee1b23e846c4feaa7f68a23ce46db0",
        "0xc84f68ea0e01fb203289508970eb21368c0db6ac034cc277349ac0108509fd49"
      ],
      "data": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    }
  ]
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bloxroute.com/base/streams/flashblocks-statediff.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
