- Generate Go stubs from the Yellowstone proto and connect with TLS, an API key and keepalive
- Subscribe to live account updates and answer server pings so the stream stays open
- Reconnect with from_slot when the server can replay, and fall back cleanly when it cannot
- Keep a slow consumer from stalling the stream and shut down without losing work
In this lesson
Yellowstone gRPC has no official Go SDK. You generate Go stubs from geyser.proto, dial the endpoint with google.golang.org/grpc, and write the stream handling yourself. This guide builds one main.go that streams live account updates. It also answers server pings, resumes with from_slot when the server can replay, keeps a slow consumer from stalling the stream, and shuts down cleanly on Ctrl+C.
Every code block below comes from a single program that we compiled with Go 1.26, grpc-go v1.75.0 and protobuf v1.36.9, against stubs generated from the v17.0.2+solana.4.4.1 proto. We ran it against the NoLimitNodes endpoint on November 27, 2026 to check TLS, the auth header and the error path. If you want the concepts first, read how a gRPC API for Solana compares with JSON-RPC and WebSockets. The same client in other languages is in the Python guide and the TypeScript walkthrough.
01What you need to build a Yellowstone gRPC client in Go#
You need Go 1.25 or newer, protoc, the two Go protoc plugins and an API key. Rust and TypeScript have published Yellowstone clients. Go does not, so you build on plain grpc-go and code you generate yourself.
The upstream repository has a Go example in examples/golang. Its README warns that it "can contains errors or be behind of the latest stable version", and its committed .pb.go files are older than the current proto. Use it to see the shape of a client, and generate your own stubs for anything you ship.
02Generate the Go stubs from geyser.proto#
Download geyser.proto and solana-storage.proto at a release tag, then run protoc with M flags that point each file at a Go package inside your module. Pin the tag: the default branch picks up new fields before most servers run them.
Both proto files declare go_package as the upstream example path, so you have to remap them. If you map both files to the same Go package, as the upstream Makefile does with its older files, the build fails. geyser.proto pulls in the storage types with import public, so protoc-gen-go writes an alias for every storage type into geyser.pb.go. Those aliases collide with the real declarations in the same package:
The fix is to give solana-storage.proto its own package. This command builds cleanly:
Before you pick a tag, ask your provider which Yellowstone version it runs, or call the unary GetVersion method. Protobuf ignores fields it doesn't know, so a newer client usually still decodes an older server's messages. The risk is the other direction: a request field the server doesn't know is silently dropped, and you get an unfiltered or unexpected stream with no error.
03Connect with TLS, an API key and keepalive#
Dial with grpc.NewClient, TLS transport credentials, a per-RPC credential that adds your key to every call, client keepalive and a larger receive limit. Putting the key in PerRPCCredentials means the stream and any unary call you add later both carry it.
Which header? Upstream Yellowstone servers read x-token, and most provider examples use it. NoLimitNodes documents x-api-key for raw gRPC clients and x-token for the SDKs. When we ran this program against grpc.mainnet.solana.nolimitnodes.com:443 with a deliberately invalid key, both headers got Unauthenticated: invalid api key, and an unrelated header got missing auth credential. So the gateway reads both. The program takes the header name from GRPC_AUTH_HEADER so you can point it at another provider.
The upstream Go example uses a 1-second keepalive timeout. We use 5 seconds so a slow link doesn't look dead. If a server answers with GOAWAY and too_many_pings, raise Time: some servers enforce a minimum ping interval.
04Subscribe to a live account stream#
A SubscribeRequest holds named filter maps. Put one entry in Accounts, set the commitment and send it as the first message on the stream. For a demo that prints something every slot with no setup, watch the Clock sysvar. Its data changes every slot.
Each update has one payload in its UpdateOneof field, so a type switch routes it. Pubkeys and signatures arrive as raw bytes. The Clock account is 40 bytes of little-endian integers, with the slot first and the Unix timestamp last, so the consumer can decode it without a library:
The name you give each filter (clock here) comes back in the update's Filters field, which tells you which filter matched when one stream carries several. To watch your own accounts, replace the Clock address with your own pubkeys (servers cap how many one filter can hold), or use Owner to match every account a program owns. Commitment is set per request, not per filter. The processed, confirmed and finalized trade-offs apply to the whole stream.
Variant: a transactions filter
Swap the accounts map for a transactions map to stream every transaction that touches a program. Set Vote and Failed to false. Vote transactions are most of mainnet's traffic. Both fields are optional bool in the proto, so Go needs pointers.
AccountInclude matches a transaction that references any listed key. AccountRequired matches only when it references all of them, and AccountExclude drops matches. The full program switches to this request when PROGRAM_ID is set.
05Answer pings so the Yellowstone gRPC stream stays open#
The server sends a Ping update on every open stream. Reply by sending a SubscribeRequest with Ping set, and the server answers with a Pong. The upstream README explains why: some load balancers close a stream when the client sends nothing for a while, and HTTP/2 keepalive frames don't count as messages.
The current upstream server answers a ping-only request with a pong and leaves your filters alone. We still clone the full request into the reply. A gateway that treats every request as a filter replacement then keeps the same filters, and an upstream server ignores the clone and just sends the pong. The reply never carries from_slot: only the first request on a stream can replay.
The ping interval varies by server version. The upstream README says 15 seconds, and the current server source sends one every 10 seconds. Either way, 30 seconds of silence is a reliable sign the stream is dead. This watchdog cancels the stream's context when that happens, which makes Recv return so the reconnect loop can take over:
06Reconnect and resume with from_slot#
Wrap the stream in a loop that stops on errors a retry can't fix, backs off with jitter on the rest, and resumes from the last slot you finished processing. from_slot on the first request asks the server to replay from that slot before it switches to live updates. It only works if the server keeps a replay buffer and the slot is still in it.
Don't send from_slot blind. In the upstream server source, a server with replay turned off fails the stream with INTERNAL: from_slot is not supported. A slot that has aged out of the buffer fails with OUT_OF_RANGE: broadcast from N is not available, last available: M. A server older than the field ignores it and streams live, so you get a gap and no error at all. The unary SubscribeReplayInfo method returns first_available, the oldest slot the server can replay. Check it first:
- Don't retry
UNAUTHENTICATED,PERMISSION_DENIEDorINVALID_ARGUMENT. The same request fails the same way every time, so retrying only adds load. - Back off with jitter, starting at 1 second and capped at 30, and reset after a stream that delivered data. Jitter stops a fleet of clients from reconnecting in lockstep after an outage.
- Expect duplicates. Resuming at
lastSlotreplays that slot again. Key transactions by signature and account updates by pubkey, slot andwrite_version. - Backfill when you can't replay. For an account stream, one
getMultipleAccountscall returns current state, which is all a gap costs you. For transactions, pagegetSignaturesForAddressback to your checkpoint and fetch each one withgetTransaction.
Replay depth differs by provider and plan, so check before you rely on it. NoLimitNodes covers replay in its keepalive and replay docs. The probe above works the same on any server.
07Handle backpressure with a goroutine and a buffered channel#
Keep Recv in its own goroutine and do the real work in another, connected by a buffered channel. The receive loop only reads, answers pings and enqueues. Decoding, database writes and the checkpoint happen in the consumer.
If processing ran inline in the receive loop, one slow write would delay the next ping reply. It would also stop the client reading from the HTTP/2 connection. Once grpc-go's flow-control window fills, the server can't send. The upstream server then disconnects subscribers that fall too far behind its broadcast, with INTERNAL: lagged to receive geyser messages.
A full buffer logs a warning and then blocks, so you notice the problem and lose no data while it lasts. For a price feed where only the latest value matters, you could drop the oldest update instead. For an indexer, blocking is right, and a full buffer that keeps happening means the consumer needs to batch its writes or run on more goroutines. The checkpoint (lastSlot) advances only after the consumer has handled an update, so a crash never skips data that was still sitting in the channel.
08Shut down cleanly with context#
Derive every context from signal.NotifyContext. On Ctrl+C or SIGTERM the context is cancelled, Recv returns, and the reconnect loop exits. Then close the channel, wait for the consumer to drain it, and close the connection.
Order matters. Close the channel only after subscribe has returned, because a send on a closed channel panics. Wait for the consumer before conn.Close() so buffered updates are written and the final checkpoint is saved. In a Kubernetes pod, keep terminationGracePeriodSeconds longer than your worst-case drain.
09The full program#
Here is the whole file. It passes go vet and builds with the stubs from section 2. Run it with your key:
Each plan includes a fixed number of concurrent gRPC streams: 2 on Pro and 10 on Ultra, as listed on the pricing page. One stream can carry many named filters, so add filters to a request before you open a second stream. Endpoint details are on the Yellowstone gRPC nodes page.
Yellowstone gRPC is the stream a Geyser plugin exposes, and every provider serves the same proto, so this client is portable. If you need decoded program events instead of raw accounts and transactions, look at Enhanced Streams. For an endpoint to run this against, create a key at dash.nolimitnodes.com.
10Sources#
- geyser.proto - rpcpool/yellowstone-grpc: SubscribeRequest, from_slot, ping, SubscribeReplayInfo and the import public of solana-storage.proto, checked November 27, 2026
- examples/golang - rpcpool/yellowstone-grpc: upstream Go example, README disclaimer, Makefile and 10 s / 1 s keepalive values, checked November 27, 2026
- yellowstone-grpc README: ping field, load balancers closing idle streams, 15 s server ping, checked November 27, 2026
- yellowstone-grpc-geyser/src/grpc.rs: from_slot error statuses, first-request-only replay, 10 s ping interval and lagged-client disconnect, checked November 27, 2026
- Keepalive | gRPC: client keepalive time and timeout, and server ping enforcement
- google.golang.org/grpc package docs: NewClient, WithPerRPCCredentials, MaxCallRecvMsgSize and the 4 MB default receive size
- Go Generated Code Guide | Protocol Buffers: go_package, M flags and module= output paths
- Sysvar Cluster Data | Anza docs: Clock sysvar address and fields
Frequently asked questions#
Is there an official Yellowstone gRPC SDK for Go?
No. Rust and TypeScript have published Yellowstone clients, but Go does not. The rpcpool/yellowstone-grpc repository has an example in examples/golang that warns it may lag the latest version. Generate your own stubs from geyser.proto at a pinned release tag and use google.golang.org/grpc directly.
Which metadata header carries the API key in a Go Yellowstone client?
Upstream Yellowstone servers read x-token. NoLimitNodes documents x-api-key for raw gRPC clients and x-token for the SDKs, and its gateway reads both. Set the header with a PerRPCCredentials implementation so the Subscribe stream and every unary call carry it, and require TLS.
How often does a Yellowstone gRPC server send pings?
The upstream README says every 15 seconds, and the current server source sends one every 10 seconds. Reply to each Ping update with a SubscribeRequest that has Ping set. Treat 30 seconds without any message as a dead stream and reconnect.
Does from_slot guarantee I never miss an update after a reconnect?
Only if the server keeps a replay buffer and your slot is still in it. Servers with replay off return INTERNAL, slots that have aged out return OUT_OF_RANGE, and servers older than the field ignore it. Call SubscribeReplayInfo first, and backfill over JSON-RPC when replay is not available.
Why does go build fail with RewardType redeclared?
geyser.proto imports solana-storage.proto with import public, so protoc-gen-go writes aliases for the storage types into geyser.pb.go. If both files are generated into one Go package, the aliases collide with the real types. Map solana-storage.proto to its own package with an M flag.