Yellowstone gRPC Quickstart

Quickstart Guide

This guide will walk you through making your first Yellowstone gRPC connection and streaming real-time Solana data.

Prerequisites

Before you begin, ensure you have:

  • Alchemy Team with PAYG or Enterprise Plan: Yellowstone gRPC is only available to PAYG (Pay-As-You-Go) and Enterprise teams
  • Create an Alchemy App: You’ll need to create an app in your Alchemy dashboard to get your endpoint URL and API key
  • Get your API Key: Your Alchemy API key will be used as the X-Token header for authentication
  • Basic understanding of gRPC concepts
  • Understanding of Solana’s slot and commitment level concepts

Authentication

Get your endpoint URL and API key from your Alchemy dashboard.

Important: Your Alchemy API Key must be passed as the X-Token header in your gRPC requests (not in the URL).

1let endpoint = "https://solana-mainnet.g.alchemy.com";
2let x_token = "ALCHEMY_API_KEY";
3
4let client = GeyserGrpcClient::build_from_shared(endpoint)?
5 .tls_config(ClientTlsConfig::new().with_native_roots())?
6 .x_token(Some(x_token))?
7 .connect()
8 .await?;

Your First Connection

Rust Example

Below is a basic example of connecting to Yellowstone gRPC with Rust and streaming all transactions.

1use anyhow::Result;
2use futures::{sink::SinkExt, stream::StreamExt};
3use solana_signature::Signature;
4use std::collections::HashMap;
5use yellowstone_grpc_client::{ClientTlsConfig, GeyserGrpcClient};
6use yellowstone_grpc_proto::geyser::{
7 CommitmentLevel, SubscribeRequest, SubscribeRequestFilterTransactions,
8 subscribe_update::UpdateOneof,
9};
10
11#[tokio::main]
12async fn main() -> Result<()> {
13 // Set up connection parameters
14 let endpoint = "https://solana-mainnet.g.alchemy.com";
15 let x_token = "ALCHEMY_API_KEY"; // Replace with your Alchemy API key
16
17 // Build and connect the gRPC client with TLS and authentication
18 let mut client = GeyserGrpcClient::build_from_shared(endpoint)?
19 .tls_config(ClientTlsConfig::new().with_native_roots())?
20 .x_token(Some(x_token))? // API key passed as X-Token header
21 .connect()
22 .await?;
23
24 // Create a bidirectional stream for subscribing to updates
25 let (mut tx, mut stream) = client.subscribe().await?;
26
27 // Send subscription request to filter for non-vote, non-failed transactions
28 tx.send(SubscribeRequest {
29 transactions: HashMap::from([(
30 "all_transactions".to_string(),
31 SubscribeRequestFilterTransactions {
32 vote: Some(false), // Exclude vote transactions
33 failed: Some(false), // Exclude failed transactions
34 ..Default::default()
35 },
36 )]),
37 commitment: Some(CommitmentLevel::Confirmed as i32), // Use confirmed commitment level
38 ..Default::default()
39 })
40 .await?;
41
42 // Process incoming transaction updates
43 while let Some(Ok(msg)) = stream.next().await {
44 if let Some(UpdateOneof::Transaction(tx)) = msg.update_oneof {
45 // Extract and display transaction signature
46 let sig = tx
47 .transaction
48 .and_then(|t| Some(Signature::try_from(t.signature.as_slice()).unwrap()))
49 .unwrap_or_default();
50 println!("Slot: {} | Signature: {}", tx.slot, sig);
51 }
52 }
53
54 Ok(())
55}

Other Languages

Yellowstone gRPC supports multiple programming languages. Choose the client that fits your stack:

Official Examples Available:

Next Steps

Now that you’ve established your first connection, explore: