SubscribeCheckpoints gRPC Method
Parameters
read_mask
object
Loading...
Returns
cursor
string
Loading...
checkpoint
object
Loading...
sequenceNumber
string
Loading...
digest
string
Loading...
summary
object
Loading...
signature
object
Loading...
contents
object
Loading...
transactions
array
Loading...
Request
grpcurl -proto ./sui/rpc/v2beta2/subscription_service.proto -H "x-token: abcde123456789" -d '{
"read_mask": {
"paths": [
"sequence_number",
"digest",
"network_total_transactions",
"previous_digest",
"epoch_rolling_gas_cost_summary",
"timestamp_ms",
"transactions"
]
}
}' docs-demo.sui-mainnet.quiknode.pro:9000 sui.rpc.v2beta2.SubscriptionService/SubscribeCheckpoints
package main
import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
"log"
"os"
"os/signal"
"syscall"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/fieldmaskpb"
pb "sui-grpc/sui/rpc/v2beta2" // Your Generated .pb.go files path
)
// QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token
// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde123456789
// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}
// token will be : abcde123456789
var (
token = "YOUR_TOKEN_NUMBER"
endpoint = "YOUR_QN_ENDPOINT:9000"
)
// Auth structure for x-token
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 (a *auth) RequireTransportSecurity() bool {
return true
}
func main() {
creds := credentials.NewTLS(&tls.Config{})
opts := []grpc.DialOption{
grpc.WithTransportCredentials(creds),
grpc.WithPerRPCCredentials(&auth{token}),
}
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer conn.Close()
client := pb.NewSubscriptionServiceClient(conn)
// Build request with field mask
req := &pb.SubscribeCheckpointsRequest{
ReadMask: &fieldmaskpb.FieldMask{
Paths: []string{
"sequence_number",
"digest",
"network_total_transactions",
"previous_digest",
"epoch_rolling_gas_cost_summary",
"timestamp_ms",
"transactions",
},
},
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
stream, err := client.SubscribeCheckpoints(ctx, req)
if err != nil {
log.Fatalf("SubscribeCheckpoints failed: %v", err)
}
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigChan
fmt.Println("\nClosing subscription...")
cancel()
}()
fmt.Println("Subscribing to checkpoints... Press Ctrl+C to stop.")
marshaler := protojson.MarshalOptions{
UseProtoNames: true,
EmitUnpopulated: true,
Indent: " ",
}
for {
resp, err := stream.Recv()
if err == io.EOF {
fmt.Println("Stream ended")
break
}
if err != nil {
log.Printf("Stream error: %v", err)
break
}
// Pretty print the response
jsonBytes, err := marshaler.Marshal(resp)
if err != nil {
log.Printf("Failed to marshal: %v", err)
continue
}
var pretty map[string]interface{}
if err := json.Unmarshal(jsonBytes, &pretty); err != nil {
log.Printf("Failed to parse JSON: %v", err)
continue
}
out, _ := json.MarshalIndent(pretty, "", " ")
fmt.Printf("Received checkpoint:\n%s\n", string(out))
}
}
import * as grpc from '@grpc/grpc-js';
import * as protoLoader from '@grpc/proto-loader';
import * as path from 'path';
// Configuration
const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2beta2/subscription_service.proto');
// QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token
// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde123456789
// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}
// token will be : abcde123456789
const endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';
const token = 'abcde123456789';
// Load protobuf definitions
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
includeDirs: [path.join(__dirname, 'protos/proto')],
});
const proto = grpc.loadPackageDefinition(packageDefinition) as any;
const SubscriptionService = proto.sui.rpc.v2beta2.SubscriptionService;
// Create secure client
const client = new SubscriptionService(endpoint, grpc.credentials.createSsl());
// Add token metadata
const metadata = new grpc.Metadata();
metadata.add('x-token', token);
// Request payload
const request = {
read_mask: {
paths: [
'sequence_number',
'digest',
'network_total_transactions',
'previous_digest',
'epoch_rolling_gas_cost_summary',
'timestamp_ms',
'transactions',
],
},
};
const call = client.SubscribeCheckpoints(request, metadata);
call.on('data', (response: any) => {
console.log('Received checkpoint:', JSON.stringify(response, null, 2));
});
call.on('error', (error: any) => {
console.error('Stream error:', error);
});
call.on('end', () => {
console.log('Stream ended');
});
console.log('Subscribing to checkpoints... Press Ctrl+C to stop.');
process.on('SIGINT', () => {
console.log('Closing subscription...');
call.cancel();
process.exit(0);
});
import grpc
import json
import signal
import sys
from google.protobuf.field_mask_pb2 import FieldMask
from google.protobuf.json_format import MessageToDict
from sui.rpc.v2beta2 import subscription_service_pb2, subscription_service_pb2_grpc
def signal_handler(sig, frame):
print('\nClosing subscription...')
sys.exit(0)
def subscribe_checkpoints():
# QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token
# For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde123456789
# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}
# token will be : abcde123456789
endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';
token = 'abcde123456789';
channel = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())
stub = subscription_service_pb2_grpc.SubscriptionServiceStub(channel)
read_mask = FieldMask(paths=[
"sequence_number",
"digest",
"network_total_transactions",
"previous_digest",
"epoch_rolling_gas_cost_summary",
"timestamp_ms",
"transactions"
])
request = subscription_service_pb2.SubscribeCheckpointsRequest(
read_mask=read_mask
)
metadata = [("x-token", token)]
return stub.SubscribeCheckpoints(request, metadata=metadata)
def parse_response_to_json(response):
return json.dumps(
MessageToDict(response, preserving_proto_field_name=True),
indent=2
)
def main():
signal.signal(signal.SIGINT, signal_handler)
print("Subscribing to checkpoints... Press Ctrl+C to stop.")
try:
response_stream = subscribe_checkpoints()
for response in response_stream:
print("Received checkpoint:")
print(parse_response_to_json(response))
except grpc.RpcError as e:
print(f"{e.code().name}: {e.details()}")
except KeyboardInterrupt:
print("\nSubscription interrupted")
if __name__ == "__main__":
main()
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free