ListEvents gRPC Method
參數
start_checkpoint
字串
載入中...
end_checkpoint
字串
載入中...
read_mask
物件
載入中...
paths
array<string>
載入中...
filter
物件
載入中...
terms
陣列
載入中...
options
物件
載入中...
上限
整數
載入中...
after
字串
載入中...
before
字串
載入中...
ordering
字串
載入中...
退貨
event
物件
載入中...
packageId
字串
載入中...
module
字串
載入中...
sender
字串
載入中...
eventType
字串
載入中...
json
物件
載入中...
checkpoint
字串
載入中...
watermark
物件
載入中...
cursor
字串
載入中...
checkpoint
字串
載入中...
結束
物件
載入中...
reason
字串
載入中...
請求
1grpcurl \2-import-path . \3-proto sui/rpc/v2/ledger_service.proto \4-H "x-token: YOUR_TOKEN_VALUE" \5-d '{6"start_checkpoint": "306133000",7"end_checkpoint": "306133070",8"read_mask": {9"paths": [10"package_id",11"module",12"sender",13"event_type",14"json",15"checkpoint"16]17},18"options": {19"limit": 220}21}' \22docs-demo.sui-mainnet.quiknode.pro:9000 \23sui.rpc.v2.LedgerService/ListEvents24
1grpcurl \2-import-path . \3-proto sui/rpc/v2/ledger_service.proto \4-H "x-token: YOUR_TOKEN_VALUE" \5-d '{6"start_checkpoint": "306133000",7"end_checkpoint": "306133070",8"read_mask": {9"paths": [10"package_id",11"module",12"sender",13"event_type",14"json",15"checkpoint"16]17},18"options": {19"limit": 220}21}' \22docs-demo.sui-mainnet.quiknode.pro:9000 \23sui.rpc.v2.LedgerService/ListEvents24
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"io"9"log"10「時間」1112"google.golang.grpc"13"google.golang.grpc"14"google.golang.org/protobuf/encoding/protojson"15"google.golang.org/protobuf/types/known/fieldmaskpb"1617pb "sui-grpc/sui/rpc/v2" // Your Generated .pb.go files path18)1920// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token21// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678922// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}23// token will be : abcde1234567892425var (26token = "YOUR_TOKEN_NUMBER"27endpoint = "YOUR_QN_ENDPOINT:9000"28)2930// Auth structure for x-token31類型 auth 結構體 {32代幣 字串33}3435func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字串) (map[字串]字串, 錯誤) {36return map[string]string{"x-token": a.token}, nil37}38func (a *auth) RequireTransportSecurity() bool {39return true40}4142func main() {43creds := credentials.NewTLS(&tls.Config{})44opts := []grpc.DialOption{45grpc.WithTransportCredentials(creds),46grpc.WithPerRPC憑證(&auth{token}),47}4849conn, err := grpc.撥號(endpoint, opts...)50如果 err != nil {51log.Fatalf("Failed to connect: %v", err)52}53延後 延遲連接.關閉()5455client := pb.NewLedgerServiceClient(conn)5657startCheckpoint := uint64(306133000)58endCheckpoint := uint64(306133070)59limit := uint32(2)6061req := &pb.ListEventsRequest{62StartCheckpoint: &startCheckpoint,63EndCheckpoint: &endCheckpoint,64ReadMask: &fieldmaskpb.FieldMask{65Paths: []string{"package_id", "module", "sender", "event_type", "json", "checkpoint"},66},67Options: &pb.QueryOptions{68Limit: &limit,69},70}7172// ListEvents is bounded by start/end checkpoint and options.limit, so the73// stream terminates on its own once the QueryEnd frame is sent.74ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)75延後 延後()7677stream, err := client.ListEvents(ctx, req)78如果 err != nil {79log.Fatalf("ListEvents failed: %v", err)80}8182marshaler := protojson.MarshalOptions{83UseProtoNames: true,84EmitUnpopulated: true,85Indent: " ",86}8788fmt.Println("Streaming events...")8990for {91resp, err := stream.Recv()92if err == io.EOF {93fmt.Println("Stream ended")94break95}96if err != nil {97log.Fatalf("Stream error: %v", err)98}99100jsonBytes, err := marshaler.Marshal(resp)101if err != nil {102log.Printf("Failed to marshal: %v", err)103continue104}105106var pretty map[string]interface{}107if err := json.Unmarshal(jsonBytes, &pretty); err != nil {108log.Printf("Failed to parse JSON: %v", err)109continue110}111112out, _ := json.MarshalIndent(pretty, "", " ")113fmt.Printf("Received frame:\n%s\n", string(out))114115if resp.GetEnd() != nil {116fmt.Printf("Query ended: %s\n", resp.GetEnd().GetReason())117}118}119}120
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"io"9"log"10「時間」1112"google.golang.grpc"13"google.golang.grpc"14"google.golang.org/protobuf/encoding/protojson"15"google.golang.org/protobuf/types/known/fieldmaskpb"1617pb "sui-grpc/sui/rpc/v2" // Your Generated .pb.go files path18)1920// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token21// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678922// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}23// token will be : abcde1234567892425var (26token = "YOUR_TOKEN_NUMBER"27endpoint = "YOUR_QN_ENDPOINT:9000"28)2930// Auth structure for x-token31類型 auth 結構體 {32代幣 字串33}3435func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字串) (map[字串]字串, 錯誤) {36return map[string]string{"x-token": a.token}, nil37}38func (a *auth) RequireTransportSecurity() bool {39return true40}4142func main() {43creds := credentials.NewTLS(&tls.Config{})44opts := []grpc.DialOption{45grpc.WithTransportCredentials(creds),46grpc.WithPerRPC憑證(&auth{token}),47}4849conn, err := grpc.撥號(endpoint, opts...)50如果 err != nil {51log.Fatalf("Failed to connect: %v", err)52}53延後 延遲連接.關閉()5455client := pb.NewLedgerServiceClient(conn)5657startCheckpoint := uint64(306133000)58endCheckpoint := uint64(306133070)59limit := uint32(2)6061req := &pb.ListEventsRequest{62StartCheckpoint: &startCheckpoint,63EndCheckpoint: &endCheckpoint,64ReadMask: &fieldmaskpb.FieldMask{65Paths: []string{"package_id", "module", "sender", "event_type", "json", "checkpoint"},66},67Options: &pb.QueryOptions{68Limit: &limit,69},70}7172// ListEvents is bounded by start/end checkpoint and options.limit, so the73// stream terminates on its own once the QueryEnd frame is sent.74ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)75延後 延後()7677stream, err := client.ListEvents(ctx, req)78如果 err != nil {79log.Fatalf("ListEvents failed: %v", err)80}8182marshaler := protojson.MarshalOptions{83UseProtoNames: true,84EmitUnpopulated: true,85Indent: " ",86}8788fmt.Println("Streaming events...")8990for {91resp, err := stream.Recv()92if err == io.EOF {93fmt.Println("Stream ended")94break95}96if err != nil {97log.Fatalf("Stream error: %v", err)98}99100jsonBytes, err := marshaler.Marshal(resp)101if err != nil {102log.Printf("Failed to marshal: %v", err)103continue104}105106var pretty map[string]interface{}107if err := json.Unmarshal(jsonBytes, &pretty); err != nil {108log.Printf("Failed to parse JSON: %v", err)109continue110}111112out, _ := json.MarshalIndent(pretty, "", " ")113fmt.Printf("Received frame:\n%s\n", string(out))114115if resp.GetEnd() != nil {116fmt.Printf("Query ended: %s\n", resp.GetEnd().GetReason())117}118}119}120
1import * as grpc from '@grpc/grpc-js';2import * as protoLoader from '@grpc/proto-loader';3import * as path from 'path';45// Configuration6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');78// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token9// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678910// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11// token will be : abcde1234567891213const endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';14const token = 'abcde123456789';1516// Load protobuf definitions17const packageDefinition = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19longs: String,20enums: String,21defaults: true,22oneofs: true,23includeDirs: [path.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) as any;27const LedgerService = proto.sui.rpc.v2.LedgerService;2829// Create secure client30const client = new LedgerService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Request payload37// ListEvents is bounded by start/end_checkpoint and options.limit, so the38// stream ends on its own — no Ctrl+C handling needed.39const request = {40start_checkpoint: '306133000',41end_checkpoint: '306133070',42read_mask: {43paths: ['package_id', 'module', 'sender', 'event_type', 'json', 'checkpoint'],44},45options: {46limit: 2,47},48};4950const call = client.ListEvents(request, metadata);5152console.log('Streaming events...');5354call.on('data', (response: any) => {55console.log('Received frame:', JSON.stringify(response, null, 2));56if (response.end) {57console.log('Query ended:', response.end.reason);58}59});6061call.on('error', (error: any) => {62console.error('Stream error:', error);63});6465call.on('end', () => {66console.log('Stream ended');67});68
1import * as grpc from '@grpc/grpc-js';2import * as protoLoader from '@grpc/proto-loader';3import * as path from 'path';45// Configuration6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');78// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token9// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678910// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11// token will be : abcde1234567891213const endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';14const token = 'abcde123456789';1516// Load protobuf definitions17const packageDefinition = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19longs: String,20enums: String,21defaults: true,22oneofs: true,23includeDirs: [path.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) as any;27const LedgerService = proto.sui.rpc.v2.LedgerService;2829// Create secure client30const client = new LedgerService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Request payload37// ListEvents is bounded by start/end_checkpoint and options.limit, so the38// stream ends on its own — no Ctrl+C handling needed.39const request = {40start_checkpoint: '306133000',41end_checkpoint: '306133070',42read_mask: {43paths: ['package_id', 'module', 'sender', 'event_type', 'json', 'checkpoint'],44},45options: {46limit: 2,47},48};4950const call = client.ListEvents(request, metadata);5152console.log('Streaming events...');5354call.on('data', (response: any) => {55console.log('Received frame:', JSON.stringify(response, null, 2));56if (response.end) {57console.log('Query ended:', response.end.reason);58}59});6061call.on('error', (error: any) => {62console.error('Stream error:', error);63});6465call.on('end', () => {66console.log('Stream ended');67});68
1import grpc2匯入 json3from google.protobuf.field_mask_pb2 import FieldMask4from google.protobuf.json_format import MessageToDict5from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc, query_options_pb267def list_events():8# Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token9# For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678910# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11# token will be : abcde1234567891213endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';14token = 'abcde123456789';1516channel = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())17stub = ledger_service_pb2_grpc.LedgerServiceStub(channel)1819read_mask = FieldMask(paths=["package_id", "module", "sender", "event_type", "json", "checkpoint"])2021# ListEvents is bounded by start/end_checkpoint and options.limit, so the22# stream ends on its own once the server sends the QueryEnd frame.23request = ledger_service_pb2.ListEventsRequest(24start_checkpoint=306133000,25end_checkpoint=306133070,26read_mask=read_mask,27options=query_options_pb2.QueryOptions(limit=2)28)2930metadata = [("x-token", token)]3132return stub.ListEvents(request, metadata=metadata)3334def parse_response_to_json(response):35return json.dumps(36MessageToDict(response, preserving_proto_field_name=True),37indent=238)3940def main():41print("Streaming events...")4243try:44response_stream = list_events()4546for response in response_stream:47print("Received frame:")48print(parse_response_to_json(response))49if response.HasField("end"):50reason = query_options_pb2.QueryEndReason.Name(response.end.reason)51print(f"Query ended: {reason}")5253print("Stream ended")5455except grpc.RpcError as e:56print(f"{e.code().name}: {e.details()}")5758if __name__ == "__main__":59main()60
1import grpc2匯入 json3from google.protobuf.field_mask_pb2 import FieldMask4from google.protobuf.json_format import MessageToDict5from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc, query_options_pb267def list_events():8# Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token9# For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678910# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11# token will be : abcde1234567891213endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';14token = 'abcde123456789';1516channel = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())17stub = ledger_service_pb2_grpc.LedgerServiceStub(channel)1819read_mask = FieldMask(paths=["package_id", "module", "sender", "event_type", "json", "checkpoint"])2021# ListEvents is bounded by start/end_checkpoint and options.limit, so the22# stream ends on its own once the server sends the QueryEnd frame.23request = ledger_service_pb2.ListEventsRequest(24start_checkpoint=306133000,25end_checkpoint=306133070,26read_mask=read_mask,27options=query_options_pb2.QueryOptions(limit=2)28)2930metadata = [("x-token", token)]3132return stub.ListEvents(request, metadata=metadata)3334def parse_response_to_json(response):35return json.dumps(36MessageToDict(response, preserving_proto_field_name=True),37indent=238)3940def main():41print("Streaming events...")4243try:44response_stream = list_events()4546for response in response_stream:47print("Received frame:")48print(parse_response_to_json(response))49if response.HasField("end"):50reason = query_options_pb2.QueryEndReason.Name(response.end.reason)51print(f"Query ended: {reason}")5253print("Stream ended")5455except grpc.RpcError as e:56print(f"{e.code().name}: {e.details()}")5758if __name__ == "__main__":59main()60