Go Client for Sui gRPC
Generate Sui v2 Go clients with explicit import mappings and connect to Dwellir using TLS, metadata authentication, and a deadline.
Sui RPC endpoint: endpoint URLs, plans and pricing.
Generate clients from the official Sui v2 definitions. The import mappings below keep generated files in one Go package.
Install dependencies
Install the Protocol Buffers compiler, protoc, through your system package manager. Then create the client project:
mkdir sui-grpc-go
cd sui-grpc-go
go mod init example.com/sui-grpc
go get google.golang.org/grpc google.golang.org/protobuf
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="$(go env GOPATH)/bin:$PATH"
git clone --depth 1 https://github.com/MystenLabs/sui-apis.git
mkdir -p protos gen
cp -R sui-apis/proto/. protos/Generate client code
Run this block in Bash. It supplies import mappings without editing the upstream proto files.
mapping=()
for file in protos/sui/rpc/v2/*.proto; do
relative=${file#protos/}
target=example.com/sui-grpc/gen/sui/rpc/v2
mapping+=("--go_opt=M${relative}=${target}")
mapping+=("--go-grpc_opt=M${relative}=${target}")
done
protoc -I./protos \
--go_out=./gen --go_opt=paths=source_relative \
--go-grpc_out=./gen --go-grpc_opt=paths=source_relative \
"${mapping[@]}" ./protos/sui/rpc/v2/*.proto
go mod tidyQuery service information
Save this as main.go:
package main
import (
"context"
"crypto/tls"
"fmt"
"log"
"os"
"time"
pb "example.com/sui-grpc/gen/sui/rpc/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
)
func main() {
apiKey := os.Getenv("DWELLIR_API_KEY")
if apiKey == "" {
log.Fatal("Set DWELLIR_API_KEY")
}
conn, err := grpc.NewClient(
"api-sui-mainnet-full.n.dwellir.com:443",
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
MinVersion: tls.VersionTLS12,
})),
)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ctx = metadata.AppendToOutgoingContext(ctx, "x-api-key", apiKey)
response, err := pb.NewLedgerServiceClient(conn).GetServiceInfo(
ctx, &pb.GetServiceInfoRequest{},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(response.GetChain(), response.GetServer(), response.GetCheckpointHeight())
}Set DWELLIR_API_KEY in your environment, then run:
go mod tidy
go run .Use other services
The execution client is pb.NewTransactionExecutionServiceClient(conn).
Object reads return response.GetObject(). Epoch reads return response.GetEpoch(), which is an epoch message, not an integer.
Use method-specific references for request fields and envelopes. See checkpoint subscriptions for stream cancellation and recovery.
Sui gRPC API - High Performance Access
Access Sui blockchain data with gRPC for high-performance, low-latency communication. Learn how to use Dwellir's Sui gRPC infrastructure for efficient blockchain queries and real-time subscriptions.
grpcurl
Inspect Dwellir Sui gRPC services with reflection, run current v2 requests, and select retained checkpoints without generating clients.