# TX Stream API

The NextBlock TX Stream API provides real-time streaming of Solana transactions filtered by program IDs. This independent service allows trading bots to subscribe to transaction streams and receive fast notifications for transactions involving specific programs, enabling quick detection of new DEX launches and trading opportunities.

To be authenticated to use **NextStream**, you have to send SOL to nextstream.sol. 5 SOL = 31 days of access. You can also send less to test the service for a few days. The minimum amount is 1 day (0.17 SOL). Upon sending SOL to nextstream.sol, the address from which you sent the SOL becomes authenticated for one concurrent connection per region. You **have to use the SOL sender wallet to authenticate** to the NextStream server.

Examples in Rust, TypeScript and Golang are available at [github.com/nextblock-ag/nextblock-stream-examples](https://github.com/nextblock-ag/nextblock-stream-examples)

## Overview

To subscribe to NextStream:

1. **Build an authentication message**: `{domain}|{publickey}|{nonce}|{timestamp}`

* `domain`: the host you are connecting to (e.g. `fra.stream.nextblock.io:22221`)
* `publickey`: the Solana public key of the account that sent the fee transaction
* `nonce`: random integer
* `timestamp`: current unix time (seconds)

2. **Sign the message** with the corresponding Solana private key.
3. **Send a subscription request** (`NextStreamSubscription`) with:

* `AuthenticationPublickey`
* `AuthenticationMessage`
* `AuthenticationSignature` (base58)
* List of `accounts` you want to filter for

4. **Receive streamed messages**, each containing a `Packet` with:

* `transaction` (binary-encoded Solana transaction)
* `slot`

## Proto Specification

```protobuf
syntax = "proto3";

package stream;

option go_package = "nextblock-stream-examples/golang-example/protos";

message NextPacket {
    bytes transaction = 1;                  // raw transaction bytes
    uint64 slot = 2;
}

message NextStreamSubscription {
    string authentication_publickey = 1;    // the publickey you used to send 5 SOL to nextstream.sol
    string authentication_message = 2;      // the finished authentication_message:
    string authentication_signature = 3;    // base58 signature, signed_message signed by authenticated_publieky

    repeated string accounts = 4;           // base58 accounts to subscribe to
}

message NextStreamNotification {
    NextPacket packet = 1;
}

service NextStreamService {
    rpc SubscribeNextStream (NextStreamSubscription) returns (stream NextStreamNotification) {}
}
```

## Available Endpoints

Choose the endpoint closest to your location for optimal latency:

* **Frankfurt**: `fra.stream.nextblock.io:22221`
* **Amsterdam**: `amsterdam.stream.nextblock.io:22221`
* **London**: `london.stream.nextblock.io:22221`
* **Singapore**: `singapore.stream.nextblock.io:22221`
* **Tokyo**: `tokyo.stream.nextblock.io:22221`
* **New York**: `ny.stream.nextblock.io:22221`
* **Salt Lake City**: `slc.stream.nextblock.io:22221`
* **Dublin**: `dublin.stream.nextblock.io:22221`
* **Vilnius**: `vilnius.stream.nextblock.io:22221`

## Examples

* [Go Example](/api/tx-stream/golang.md) - Complete Go implementation with connection setup
* [Rust Example](/api/tx-stream/rust.md) - Rust implementation using Tonic
* [TypeScript Example](/api/tx-stream/typescript.md) - TypeScript implementation for Node.js
* [HTTP Example](/api/tx-stream/http.md) - HTTP alternatives

## Use Cases

1. **Trading Bots**: Real-time transaction detection for automated trading strategies and sniping new DEX launches

## Best Practices

1. **Choose optimal endpoint**: Use the endpoint closest to your location
2. **Filter efficiently**: Subscribe only to programs you need to reduce bandwidth
3. **Handle reconnections**: Implement automatic reconnection logic
4. **Process quickly**: Handle incoming transactions efficiently to avoid backlog
5. **Use connection pooling**: For high-throughput applications
6. **Monitor connection health**: Implement heartbeat/keepalive mechanisms


---

# 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.nextblock.io/api/tx-stream.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.
