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 Yellowstone 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.
There are two authentication methods:
- Basic Authentication
- x-token Authentication
This document provides implementation details for both methods.
Basic Authentication
The getClientWithBasicAuth
function demonstrates how to handle authentication using Basic Authentication. It encodes the credentials in base64 and adds them to the authorization
header.
Implementation
import (
"context"
"crypto/tls"
"encoding/base64"
"fmt"
"log"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
func getClientWithBasicAuth(endpoint, token string) (*grpc.ClientConn, error) {
target := endpoint + ".solana-mainnet.quiknode.pro:10000"
conn, err := grpc.Dial(target,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
grpc.WithPerRPCCredentials(basicAuth{
username: endpoint,
password: token,
}),
)
if err != nil {
return nil, fmt.Errorf("unable to dial endpoint: %w", err)
}
return conn, nil
}
type basicAuth struct {
username string
password string
}
func (b basicAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) {
auth := b.username + ":" + b.password
encoded := base64.StdEncoding.EncodeToString([]byte(auth))
return map[string]string{"authorization": "Basic " + encoded}, nil
}
func (basicAuth) RequireTransportSecurity() bool {
return true
}
Usage
conn, err := getClientWithBasicAuth("ENDPOINT_NAME", "TOKEN")
if err != nil {
log.Fatalf("failed to connect: %v", err)
}
defer conn.Close()
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.