Cosmos SDK and CosmWasm functionality on Sei are deprecated in favor of EVM-only. For more details, see SIP-3 and the governance proposal.
With a Quicknode Sei endpoint, you can interact with the Cosmos SDK using either REST or gRPC. The REST API serves JSON over HTTP, making it easy to fetch balances, transactions, and other on-chain data with standard web tools. The gRPC API uses Protocol Buffers over HTTP/2, offering faster, strongly typed requests and streaming support for real-time data. Use REST for quick, human-readable integrations, and gRPC when you need high-performance backend services at scale.
Authentication Required for Sei gRPC
To ensure secure access to Sei gRPC, authentication is required before calling any method. Quicknode endpoints consist of two components: the endpoint e o correspondente ficha. Use these to configure a gRPC client with authentication credentials prior to making requests.
Authentication for the Sei gRPC can be handled in two ways:
- Autenticação básica
- Autenticação x-token
Throughout this documentation, we call either the getClientWithBasicAuth ou getClientWithXToken functions to demonstrate how to handle these authentication mechanisms.
Autenticação básica
O getClientWithBasicAuth Esta função demonstra como gerir a autenticação utilizando a Autenticação Básica, que codifica as credenciais em base64. Segue-se a implementação do código da getClientWithBasicAuth função, bem como o basicAuth implementação das credenciais RPC:
import (
"contexto"
"crypto/tls"
"encoding/base64"
"fmt"
"google.golang.grpc"
"google.golang.grpc"
)
func getClientWithBasicAuth(endpoint, token string) (*grpc.ClientConn, error) {
target := endpoint + ".sei-pacific.quiknode.pro:9090" // for TLS connections
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
}
// basicAuth implements the credentials.PerRPCCredentials interface to support basic authentication for grpc requests.
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
enc := base64.StdEncoding.EncodeToString([]byte(auth))
return map[string]string{"authorization": "Basic " + enc}, nil
}
func (basicAuth) RequireTransportSecurity() bool {
return false
}
O getClientWithBasicAuth Esta função configura um gRPC com as opções de segurança necessárias e estabelece uma ligação ao endpoint especificado endpoint porta 9090. Aceita o endpoint e o token como parâmetros de entrada e devolve uma ligação gRPC , que pode utilizar para efetuar chamadas à API autenticadas.
conn, err := getClientWithBasicAuth("ENDPOINT_NAME", "TOKEN")
if err != nil {
log.Fatalf("err: %v", err)
}
defer conn.Close()
Autenticação x-token
O getClientWithXToken function demonstrates how to handle authentication using an x-token. This method attaches the token to the x-token header of each request.
import (
"contexto"
"crypto/tls"
"fmt"
"google.golang.grpc"
"google.golang.grpc"
)
func getClientWithXToken(endpoint, token string) (*grpc.ClientConn, error) {
target := endpoint + ".sei-pacific.quiknode.pro:9090" // for TLS connections
conn, err := grpc.Dial(target,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
grpc.WithPerRPCCredentials(auth{
token: token,
}),
)
if err != nil {
return nil, fmt.Errorf("Unable to dial endpoint %w", err)
}
return conn, nil
}
// auth implements the credentials.PerRPCCredentials interface to support x-token authentication for grpc requests.
type auth struct {
token string
}
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
return map[string]string{
"x-token": a.token,
}, nil
}
func (auth) RequireTransportSecurity() bool {
return false
}
This method configures a gRPC client similarly to the basic authentication example, but it attaches the authentication token in the x-token header. Here's how you can use this function to make API calls:
conn, err := getClientWithXToken("ENDPOINT_NAME", "TOKEN")
if err != nil {
log.Fatalf("err: %v", err)
}
defer conn.Close()