Yellowstone gRPC Client in Rust: Subscribe to Transactions
Subscribe to Solana transactions with the yellowstone-grpc-client Rust crate: connect with x-token, filter transactions, answer pings, resume with from_slot.
To stream Solana transactions in Rust, connect with GeyserGrpcClient from the yellowstone-grpc-client crate, send a SubscribeRequest with a transactions filter, and read the stream. To keep it running, answer the server's pings, keep HTTP/2 alive, and on a drop reconnect with from_slot set to the last slot you finished.
This post builds that client step by step, then gives the whole program. It compiles against yellowstone-grpc-client 16.0.1 and yellowstone-grpc-proto 14.0.1, the versions our gRPC docs use; we checked it with cargo check on 3 December 2026. Every call in it is in those two crates.
Disclosure: AllenHark sells Yellowstone gRPC. The examples connect to AllenHark's Frankfurt endpoint; any Yellowstone gRPC endpoint works with a different URL and token.
Add the crates
[dependencies]
yellowstone-grpc-client = "16.0.1"
yellowstone-grpc-proto = "14.0.1"
tokio = { version = "1", features = ["full"] }
futures = "0.3"
anyhow = "1"
bs58 = "0.5" # to print signatures the way explorers show themyellowstone-grpc-proto builds its protobuf code with a bundled protoc, so you don't need to install one.
Connect, with or without an x-token
let mut client = GeyserGrpcClient::build_from_shared("http://88.216.36.108:10001")?
// No token from an allowlisted IP; set ALLENHARK_KEY to send your API key as x-token
.x_token(std::env::var("ALLENHARK_KEY").ok())?
.connect_timeout(Duration::from_secs(10))
.max_decoding_message_size(64 * 1024 * 1024)
.connect()
.await?;Three things in those lines trip people up:
- The token.
x_tokentakes anOption. On AllenHark, a server whose IP is on your allowlist sendsNone; from any other address, send the API key that comes with new subscriptions. Other providers that use an x-token take their key here too. The header isx-token, notx-api-key. - The scheme. AllenHark's endpoint is plaintext HTTP/2, so the URL starts with
http://. A provider with TLS useshttps://. - The message size. tonic refuses any message over 4 MiB by default, and a busy slot is bigger. Raise the limit or the stream fails with
decoded message length too large.
Filter transactions
A SubscribeRequest holds maps of named filters. The name you pick ("pump" below) comes back in filters on every update it matches, so one stream can carry several filters.
let mut transactions = HashMap::new();
transactions.insert(
"pump".to_string(),
SubscribeRequestFilterTransactions {
vote: Some(false),
failed: Some(false),
account_include: vec![PUMP_FUN.to_string()],
..Default::default()
},
);The fields of SubscribeRequestFilterTransactions:
| Field | What it does |
|---|---|
vote | Some(false) drops vote transactions, which are most of the traffic. |
failed | Some(false) drops failed transactions. |
account_include | A transaction matches if it touches any of these accounts. |
account_required | A transaction matches only if it touches all of these. |
account_exclude | A transaction that touches any of these is dropped. |
signature | Exactly one transaction, by signature. |
Each update arrives as UpdateOneof::Transaction, with the slot and a transaction field holding the signature, the transaction and its status meta.
Answer pings and keep the connection alive
A stream that dies without a clean close looks exactly like a quiet one. Two things catch it:
- Pings. Yellowstone servers send a ping update on every open stream. Answer with a request that sets only
ping; it leaves your filters as they are.subscribe_with_requesthands you the sink to write it to. - HTTP/2 keepalive, so a dead connection fails instead of hanging. Keep the interval at 10 seconds or more, since gRPC servers can close connections that ping too often.
let (mut sink, mut stream) = client
.subscribe_with_request(Some(request(*checkpoint)))
.await?;
// in the read loop:
Some(UpdateOneof::Ping(_)) => {
sink.send(SubscribeRequest {
ping: Some(SubscribeRequestPing { id: 1 }),
..Default::default()
})
.await?;
}The keepalive is three builder calls: .http2_keep_alive_interval(Duration::from_secs(10)), .keep_alive_timeout(Duration::from_secs(5)) and .keep_alive_while_idle(true).
Reconnect with from_slot
Since yellowstone-grpc-client 14.0.0, subscribe and subscribe_with_request don't reconnect on their own: when the connection drops, the stream ends. Two ways to carry on:
subscribe_with_reconnect, the crate's bank-aware reconnecting stream. It needsprocessedcommitment and nofrom_slotof your own; our reconnect guide covers it.- Your own loop, below, at
confirmed. Add a slots filter withfilter_by_commitment: Some(true): you get one slot update per slot, after that slot's transactions. Keep that slot as your checkpoint, and on reconnect send the whole request again withfrom_slot: Some(checkpoint). Resuming from the checkpoint itself replays one slot you already have, so drop transactions by signature.
The server keeps nothing about you between connections, so every reconnect sends every filter again. How far back from_slot can go is the provider's replay window: AllenHark keeps about 48 hours.
The whole program
// Cargo.toml: yellowstone-grpc-client = "16.0.1", yellowstone-grpc-proto = "14.0.1",
// tokio = { version = "1", features = ["full"] }, futures = "0.3", anyhow = "1", bs58 = "0.5"
use std::{collections::HashMap, time::Duration};
use futures::{SinkExt, StreamExt};
use yellowstone_grpc_client::{GeyserGrpcClient, GeyserGrpcClientError};
use yellowstone_grpc_proto::{
geyser::{
subscribe_update::UpdateOneof, CommitmentLevel, SubscribeRequest,
SubscribeRequestFilterSlots, SubscribeRequestFilterTransactions, SubscribeRequestPing,
},
tonic::{Code, Status},
};
/// AllenHark Frankfurt. Plaintext HTTP/2: http://, never https://.
const ENDPOINT: &str = "http://88.216.36.108:10001";
/// The Pump.fun program: every transaction that touches it.
const PUMP_FUN: &str = "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P";
/// The whole request, sent again on every connection: the server keeps nothing between them.
fn request(from_slot: Option<u64>) -> SubscribeRequest {
let mut transactions = HashMap::new();
transactions.insert(
"pump".to_string(),
SubscribeRequestFilterTransactions {
vote: Some(false),
failed: Some(false),
account_include: vec![PUMP_FUN.to_string()],
..Default::default()
},
);
// One slot update per slot, sent once the slot reaches the request's commitment
let mut slots = HashMap::new();
slots.insert(
"checkpoint".to_string(),
SubscribeRequestFilterSlots {
filter_by_commitment: Some(true),
..Default::default()
},
);
SubscribeRequest {
transactions,
slots,
commitment: Some(CommitmentLevel::Confirmed as i32),
from_slot,
..Default::default()
}
}
/// One connection: subscribe, answer pings, read until the stream ends or fails.
async fn stream_once(
checkpoint: &mut Option<u64>,
seen: &mut HashMap<Vec<u8>, u64>,
) -> anyhow::Result<()> {
let mut client = GeyserGrpcClient::build_from_shared(ENDPOINT)?
// No token from an allowlisted IP; set ALLENHARK_KEY to send your API key as x-token
.x_token(std::env::var("ALLENHARK_KEY").ok())?
.connect_timeout(Duration::from_secs(10))
// HTTP/2 pings, so a dead connection fails instead of hanging
.http2_keep_alive_interval(Duration::from_secs(10))
.keep_alive_timeout(Duration::from_secs(5))
.keep_alive_while_idle(true)
// A busy slot is bigger than the 4 MiB default
.max_decoding_message_size(64 * 1024 * 1024)
.connect()
.await?;
// Resume from the checkpoint itself: one slot of overlap, which `seen` removes
let (mut sink, mut stream) = client
.subscribe_with_request(Some(request(*checkpoint)))
.await?;
while let Some(update) = stream.next().await {
match update?.update_oneof {
Some(UpdateOneof::Transaction(tx)) => {
let Some(info) = tx.transaction else { continue };
if seen.insert(info.signature.clone(), tx.slot).is_none() {
// First time this signature arrives: act on it here
println!(
"{} slot {}",
bs58::encode(&info.signature).into_string(),
tx.slot
);
}
}
Some(UpdateOneof::Slot(slot)) => {
// Every transaction of this slot has arrived: it is the new checkpoint
*checkpoint = Some(slot.slot);
seen.retain(|_, at| *at + 1_000 >= slot.slot);
}
Some(UpdateOneof::Ping(_)) => {
// A request with only `ping` set leaves the filters as they are
sink.send(SubscribeRequest {
ping: Some(SubscribeRequestPing { id: 1 }),
..Default::default()
})
.await?;
}
_ => {}
}
}
Ok(())
}
/// The gRPC status behind an error, if there is one.
fn status_of(err: &anyhow::Error) -> Option<&Status> {
err.downcast_ref::<Status>()
.or_else(|| match err.downcast_ref::<GeyserGrpcClientError>() {
Some(GeyserGrpcClientError::TonicStatus(status)) => Some(status),
_ => None,
})
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut checkpoint: Option<u64> = None; // None: start at the tip
let mut seen: HashMap<Vec<u8>, u64> = HashMap::new(); // signature -> slot
let mut backoff = Duration::from_millis(250);
loop {
let before = checkpoint;
match stream_once(&mut checkpoint, &mut seen).await {
Ok(()) => eprintln!("stream ended"),
Err(err) => {
let status = status_of(&err);
let code = status.map(Status::code);
// Access or request errors: retrying only hammers the server
if matches!(
code,
Some(
Code::PermissionDenied
| Code::Unauthenticated
| Code::InvalidArgument
| Code::Unimplemented
)
) {
return Err(err);
}
// OUT_OF_RANGE also covers a message over the size limit; this is the replay refusal
let replay_refused = code == Some(Code::OutOfRange)
&& status.is_some_and(|s| !s.message().contains("message length"));
if replay_refused {
// from_slot is older than the replay window: resume at the tip, backfill from RPC
eprintln!("replay refused from {checkpoint:?}: {err}");
checkpoint = None;
} else {
eprintln!("stream error: {err}");
}
}
}
if checkpoint != before {
backoff = Duration::from_millis(250); // the last stream made progress
}
eprintln!("reconnecting from {checkpoint:?} in {backoff:?}");
tokio::time::sleep(backoff).await;
backoff = (backoff * 2).min(Duration::from_secs(30));
}
}Run it with cargo run, or ALLENHARK_KEY=your_key cargo run from a server that is not on your allowlist. It prints each Pump.fun transaction's signature and slot once, carries on through drops, and stops on errors a retry can't fix.
Common errors
| Error | What it means | Fix |
|---|---|---|
PERMISSION_DENIED: Unauthorized IP | On AllenHark: the address is not on your allowlist and no valid key was sent. | Add the IP in the console, or set ALLENHARK_KEY. |
UNAUTHENTICATED | The provider wanted a token and got none, or a wrong one. | Check the key, and that it goes through x_token. |
A transport error at connect() | Often https:// against a plaintext endpoint, or the reverse. | Use the scheme the provider documents: http:// for AllenHark. |
OUT_OF_RANGE: Error, decoded message length too large | A message was bigger than the client's limit, 4 MiB by default. | Raise max_decoding_message_size. |
OUT_OF_RANGE: broadcast from <slot> is not available | from_slot is older than the replay window. | Resubscribe at the tip, or from first_available (subscribe_replay_info), and backfill the gap from RPC. |
RESOURCE_EXHAUSTED | On AllenHark: more open streams from one address than your plan allows. | Close the old stream before opening a new one. |
INTERNAL: lagged to send an update | Your client read too slowly and the server dropped the stream. | Do the work outside the read loop, for example through a channel. |
| The stream ends after an upgrade | Since 14.0.0, subscribe no longer reconnects. | Use subscribe_with_reconnect, or a loop like the one above. |
AllenHark Yellowstone gRPC
AllenHark's Yellowstone gRPC streams from Frankfurt (88.216.36.108:10001) and Amsterdam (84.32.104.38:10001) over plaintext HTTP/2. You connect from an allowlisted IP with no token, or with your API key as x-token from anywhere. from_slot replay keeps about 48 hours. On Standard, each connection you buy is one Subscribe stream; Dedicated gRPC has no rate limits. Plans and prices are on the pricing page. Coming from Helius? See the LaserStream alternative.
FAQ
Which yellowstone-grpc-client version should I use?
The examples here use yellowstone-grpc-client 16.0.1 with yellowstone-grpc-proto 14.0.1. Keep the two at versions released together: yellowstone-grpc-client 16.0.1 itself depends on yellowstone-grpc-proto 14.0.1.
How do I pass an x-token in the Rust client?
Call .x_token(Some(key)) on the builder before .connect(). It takes an Option, so .x_token(std::env::var("ALLENHARK_KEY").ok()) sends a key only when the variable is set, which suits an allowlisted server too.
How do I subscribe to one program's transactions?
Put the program's address in account_include of a SubscribeRequestFilterTransactions, with vote: Some(false) and, if you only want successful ones, failed: Some(false).
Do I have to answer pings?
Yes, answer them: it is one small request, and a request with only ping set leaves your filters unchanged. With HTTP/2 keepalive as well, a dead connection shows up as an error instead of silence.
How do I resume after a disconnect without missing transactions?
Keep the last slot you finished, reconnect with the full request and from_slot set to it, and drop duplicates by signature. If the slot is older than the replay window, resubscribe at the tip and backfill from RPC.
Related reading
- Reconnect Yellowstone gRPC without missing transactions
- Why your Yellowstone gRPC stream lags or misses events
- Best Yellowstone gRPC providers in 2026
- Solana gRPC docs: Subscribe reference
Sources
Checked 3 December 2026.
yellowstone-grpc-client16.0.1 source on crates.io: the builder (x_token, keepalive,max_decoding_message_size),subscribe_with_request,subscribe_with_reconnect,subscribe_replay_infoyellowstone-grpc-proto14.0.1,geyser.proto:SubscribeRequest,from_slot,SubscribeRequestFilterTransactions,SubscribeRequestPing- tonic 0.14 source: the 4 MiB default receive limit and its
OUT_OF_RANGEerror - The Yellowstone gRPC repository and our reconnect guide for the server's ping, replay and lag behaviour
