Skip to main content

Making Solana gRPC Requests with Go

Updated on
Oct 21, 2026

Solana gRPC is available on Mainnet and Devnet for Scale and Business customers. The example below uses Mainnet. For Devnet, use your Solana Devnet endpoint hostname and token; see Endpoint and Token Configuration.

Overview​

Go is a statically-typed, compiled language known for its simplicity, efficiency, and strong concurrency support. Follow the official installation guide to install Go. Verify the installation:

go version

Authentication for Go Requests​

To securely access Solana gRPC (Yellowstone-compatible Geyser gRPC), authentication is required. Quicknode endpoints consist of two components: endpoint name and token. You must use these components to configure a gRPC client with authentication credentials.

Solana gRPC uses x-token authentication.


x-token Authentication​

The getClientWithXToken function demonstrates how to authenticate using an x-token. This method attaches the token to the x-token header of each request.

Implementation​

import (
"context"
"crypto/tls"
"fmt"
"log"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

func getClientWithXToken(endpoint, token string) (*grpc.ClientConn, error) {
target := endpoint + ".solana-mainnet.quiknode.pro:443"
conn, err := grpc.NewClient(target,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
grpc.WithPerRPCCredentials(xTokenAuth{
token: token,
}),
)
if err != nil {
return nil, fmt.Errorf("unable to dial endpoint: %w", err)
}
return conn, nil
}

type xTokenAuth struct {
token string
}

func (x xTokenAuth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
return map[string]string{"x-token": x.token}, nil
}

func (xTokenAuth) RequireTransportSecurity() bool {
return true
}

Usage​

conn, err := getClientWithXToken("ENDPOINT_NAME", "TOKEN")
if err != nil {
log.Fatalf("failed to connect: %v", err)
}
defer conn.Close()


Note:

To learn how to split your Solana gRPC-enabled URL into endpoint and token, refer to this section - Endpoint and Token Configuration

The below section provides a step-by-step process to set up a Go environment for making Solana gRPC requests. The instructions include setting up Go, configuring dependencies, and implementing authentication mechanisms.

Initiating the Go Project for Solana gRPC​

Step 1: Create a New Project Directory​

Create a dedicated directory for your Solana gRPC project and navigate into it:

mkdir yellowstone-grpc
cd yellowstone-grpc

Step 2: Initialize a Go Module​

Initialize a new Go module for your project:

go mod init yellowstone-grpc # directory name

Step 3: Install Required Dependencies​

Install the necessary Go dependencies for gRPC, Protocol Buffers, and Base58 encoding:

go get google.golang.org/grpc
go get google.golang.org/protobuf
go get github.com/mr-tron/base58

Step 4: Organize Your Project Directory​

First, create a proto folder to store the .pb.go files:

mkdir proto

You need three generated files in the proto directory:


  • geyser.pb.go
  • geyser_grpc.pb.go
  • solana-storage.pb.go

Generate them from the yellowstone-grpc-proto definitions at tag v16.1.4+solana.4.3.2 or later. Install the protoc plugins, then run protoc against the .proto files:

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
export PATH="$PATH:$(go env GOPATH)/bin"

protoc \
--go_out=./proto --go_opt=paths=source_relative \
--go-grpc_out=./proto --go-grpc_opt=paths=source_relative \
--proto_path=/path/to/yellowstone-grpc-proto/proto \
/path/to/yellowstone-grpc-proto/proto/*.proto

Do not use the pre-generated .pb.go files in the repository's examples/golang/proto directory. They are not regenerated on every proto release, and their Message type currently ends at AddressTableLookups with no Config field, so a version 1 transaction decodes with its compute and fee settings dropped and no error raised.

The project structure might look like this:

yellowstone-grpc/
├── go.mod
├── go.sum
├── proto/
│ ├── geyser.pb.go
│ ├── geyser_grpc.pb.go
│ ├── solana-storage.pb.go

Step 5: Create a Main Go File​

Set up a main Go file for implementing client or server logic:

touch main.go

You can copy and paste the following sample code into your main.go file to get started. The example demonstrates how to interact with a gRPC service to fetch the latest blockhash information.

package main

import (
"context"
"crypto/tls"
"fmt"
"log"
"time"
// "encoding/json"
// "github.com/mr-tron/base58"

pb "yellowstone-grpc/proto" // proto directory path

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/keepalive"
)

var (
endpoint = "example-guide-demo.solana-mainnet.quiknode.pro:443"
token = "123456789abcdefghijklmnopquerst"
)

var kacp = keepalive.ClientParameters{
Time: 10 * time.Second,
Timeout: time.Second,
PermitWithoutStream: true,
}

// tokenAuth implements the credentials.PerRPCCredentials interface
type tokenAuth struct {
token string
}

func (t tokenAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) {
return map[string]string{"x-token": t.token}, nil
}

func (tokenAuth) RequireTransportSecurity() bool {
return true
}

func main() {
opts := []grpc.DialOption{
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
grpc.WithKeepaliveParams(kacp),
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Name)),
grpc.WithPerRPCCredentials(tokenAuth{token: token}),
}

conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer conn.Close()

client := pb.NewGeyserClient(conn)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

latestBlockHash, err := client.GetLatestBlockhash(ctx, &pb.GetLatestBlockhashRequest{})
if err != nil {
log.Fatalf("Failed to get latest blockhash: %v", err)
}

fmt.Printf("Latest Blockhash Information: ")
fmt.Printf(" Blockhash: %+v", latestBlockHash)
}

Importing google.golang.org/grpc/encoding/gzip registers the gzip compressor so the server can compress responses. zstd requires the third-party github.com/mostynb/go-grpc-compression/zstd compressor, see Compression.

Step 6: Run Your Code​

Before running your code, clean up and ensure all dependencies are correctly resolved:

go mod tidy

Build and run the project using:

go run main.go

Additional Resources​

For more information about working with Solana gRPC in Go, refer to Monitor Solana Liquidity Pools with Solana gRPC (Go).