GetTransaction gRPC Method
參數
digest
字串
必填
載入中...
read_mask
物件
載入中...
paths
array<string>
載入中...
退貨
交易
物件
載入中...
digest
字串
載入中...
交易
物件
載入中...
bcs
物件
載入中...
名稱
字串
載入中...
值
字串
載入中...
digest
字串
載入中...
版本
整數
載入中...
種類
物件
載入中...
programmableTransaction
物件
載入中...
輸入
陣列
載入中...
種類
字串
載入中...
objectId
字串
載入中...
版本
字串
載入中...
mutable
布林值
載入中...
pure
字串
載入中...
commands
陣列
載入中...
moveCall
物件
載入中...
package
字串
載入中...
module
字串
載入中...
function
字串
載入中...
typeArguments
陣列
載入中...
arguments
陣列
載入中...
種類
字串
載入中...
輸入
整數
載入中...
結果
整數
載入中...
寄件人
字串
載入中...
gasPayment
物件
載入中...
objects
陣列
載入中...
objectId
字串
載入中...
版本
字串
載入中...
digest
字串
載入中...
所有者
字串
載入中...
價格
字串
載入中...
budget
字串
載入中...
expiration
物件
載入中...
種類
字串
載入中...
effects
物件
載入中...
bcs
物件
載入中...
名稱
字串
載入中...
值
字串
載入中...
digest
字串
載入中...
版本
整數
載入中...
狀態
物件
載入中...
成功
布林值
載入中...
時代
字串
載入中...
gasUsed
物件
載入中...
computationCost
字串
載入中...
storageCost
字串
載入中...
storageRebate
字串
載入中...
nonRefundableStorageFee
字串
載入中...
transactionDigest
字串
載入中...
gasObject
物件
載入中...
eventsDigest
字串
載入中...
dependencies
陣列
載入中...
digest
字串
載入中...
lamportVersion
字串
載入中...
changedObjects
陣列
載入中...
unchangedConsensusObjects
陣列
載入中...
unchangedSharedObjects
陣列
載入中...
種類
字串
載入中...
objectId
字串
載入中...
版本
字串
載入中...
digest
字串
載入中...
活動
物件
載入中...
bcs
物件
載入中...
名稱
字串
載入中...
值
字串
載入中...
digest
字串
載入中...
活動
陣列
載入中...
packageId
字串
載入中...
module
字串
載入中...
寄件人
字串
載入中...
eventType
字串
載入中...
contents
物件
載入中...
名稱
字串
載入中...
值
字串
載入中...
json
物件
載入中...
balanceManagerId
字串
載入中...
baseAssetQuantityCanceled
字串
載入中...
clientOrderId
字串
載入中...
isBid
布林值
載入中...
orderId
字串
載入中...
originalQuantity
字串
載入中...
poolId
字串
載入中...
價格
字串
載入中...
時間戳記
字串
載入中...
trader
字串
載入中...
時間戳記
字串
載入中...
請求
1grpcurl \2-import-path . \3-proto sui/rpc/v2/ledger_service.proto \4-H "x-token: YOUR_TOKEN_VALUE" \5-d '{6"digest": "HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G",7"read_mask": {8"paths": [9"digest",10"transaction",11"effects",12"events"13]14}15}' \16docs-demo.sui-mainnet.quiknode.pro:9000 \17sui.rpc.v2.LedgerService/GetTransaction
1grpcurl \2-import-path . \3-proto sui/rpc/v2/ledger_service.proto \4-H "x-token: YOUR_TOKEN_VALUE" \5-d '{6"digest": "HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G",7"read_mask": {8"paths": [9"digest",10"transaction",11"effects",12"events"13]14}15}' \16docs-demo.sui-mainnet.quiknode.pro:9000 \17sui.rpc.v2.LedgerService/GetTransaction
1package main23import (4"context"5"crypto/tls"6"encoding/json"7"fmt"8"log"9"time"1011"google.golang.org/grpc"12"google.golang.org/grpc/credentials"13"google.golang.org/protobuf/encoding/protojson"14"google.golang.org/protobuf/types/known/fieldmaskpb"1516pb "sui-grpc/sui/rpc/v2" // Your Generated .pb.go files path17)1819// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token20// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678921// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}22// token will be : abcde1234567892324var (25token = "YOUR_TOKEN_NUMBER"26endpoint = "YOUR_QN_ENDPOINT:9000"27)2829// Auth structure for x-token30type auth struct {31token string32}3334func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {35return map[string]string{36"x-token": a.token,37}, nil38}3940func (a *auth) RequireTransportSecurity() bool {41return true42}4344func main() {45// TLS credentials46creds := credentials.NewTLS(&tls.Config{})47opts := []grpc.DialOption{48grpc.WithTransportCredentials(creds),49grpc.WithPerRPCCredentials(&auth{token}),50}5152conn, err := grpc.Dial(endpoint, opts...)53if err != nil {54log.Fatalf("Failed to connect: %v", err)55}56defer conn.Close()5758client := pb.NewLedgerServiceClient(conn)5960txDigest := "HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G"6162fieldMask := &fieldmaskpb.FieldMask{63Paths: []string{"events", "effects"},64}6566req := &pb.GetTransactionRequest{67Digest: &txDigest,68ReadMask: fieldMask,69}7071ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)72defer cancel()7374resp, err := client.GetTransaction(ctx, req)75if err != nil {76log.Fatalf("GetTransaction failed: %v", err)77}7879marshaler := protojson.MarshalOptions{80UseProtoNames: true,81EmitUnpopulated: true,82Indent: " ",83}8485jsonBytes, err := marshaler.Marshal(resp)86if err != nil {87log.Fatalf("Failed to marshal response to JSON: %v", err)88}8990var prettyJSON map[string]interface{}91if err := json.Unmarshal(jsonBytes, &prettyJSON); err != nil {92log.Fatalf("Failed to unmarshal JSON: %v", err)93}9495prettyJSONBytes, err := json.MarshalIndent(prettyJSON, "", " ")96if err != nil {97log.Fatalf("Failed to format JSON: %v", err)98}99100fmt.Println(string(prettyJSONBytes))101}102
1package main23import (4"context"5"crypto/tls"6"encoding/json"7"fmt"8"log"9"time"1011"google.golang.org/grpc"12"google.golang.org/grpc/credentials"13"google.golang.org/protobuf/encoding/protojson"14"google.golang.org/protobuf/types/known/fieldmaskpb"1516pb "sui-grpc/sui/rpc/v2" // Your Generated .pb.go files path17)1819// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token20// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678921// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}22// token will be : abcde1234567892324var (25token = "YOUR_TOKEN_NUMBER"26endpoint = "YOUR_QN_ENDPOINT:9000"27)2829// Auth structure for x-token30type auth struct {31token string32}3334func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {35return map[string]string{36"x-token": a.token,37}, nil38}3940func (a *auth) RequireTransportSecurity() bool {41return true42}4344func main() {45// TLS credentials46creds := credentials.NewTLS(&tls.Config{})47opts := []grpc.DialOption{48grpc.WithTransportCredentials(creds),49grpc.WithPerRPCCredentials(&auth{token}),50}5152conn, err := grpc.Dial(endpoint, opts...)53if err != nil {54log.Fatalf("Failed to connect: %v", err)55}56defer conn.Close()5758client := pb.NewLedgerServiceClient(conn)5960txDigest := "HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G"6162fieldMask := &fieldmaskpb.FieldMask{63Paths: []string{"events", "effects"},64}6566req := &pb.GetTransactionRequest{67Digest: &txDigest,68ReadMask: fieldMask,69}7071ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)72defer cancel()7374resp, err := client.GetTransaction(ctx, req)75if err != nil {76log.Fatalf("GetTransaction failed: %v", err)77}7879marshaler := protojson.MarshalOptions{80UseProtoNames: true,81EmitUnpopulated: true,82Indent: " ",83}8485jsonBytes, err := marshaler.Marshal(resp)86if err != nil {87log.Fatalf("Failed to marshal response to JSON: %v", err)88}8990var prettyJSON map[string]interface{}91if err := json.Unmarshal(jsonBytes, &prettyJSON); err != nil {92log.Fatalf("Failed to unmarshal JSON: %v", err)93}9495prettyJSONBytes, err := json.MarshalIndent(prettyJSON, "", " ")96if err != nil {97log.Fatalf("Failed to format JSON: %v", err)98}99100fmt.Println(string(prettyJSONBytes))101}102
1import * as grpc from '@grpc/grpc-js';2import * as protoLoader from '@grpc/proto-loader';3import * as path from 'path';45// Path to the proto file6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');78// Load the proto definition9const packageDefinition = protoLoader.loadSync(PROTO_PATH, {10keepCase: true,11longs: String,12enums: String,13defaults: true,14oneofs: true,15includeDirs: [path.join(__dirname, 'protos/proto')],16});1718const proto = grpc.loadPackageDefinition(packageDefinition) as any;19const LedgerService = proto.sui.rpc.v2.LedgerService;2021// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token22// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678923// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}24// token will be : abcde1234567892526const endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';27const token = 'abcde123456789';2829// Create client with TLS30const client = new LedgerService(endpoint, grpc.credentials.createSsl());3132// Prepare metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Replace this with your actual transaction digest37const txDigest = 'HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G';3839// Prepare request40const request = {41digest: txDigest,42read_mask: {43paths: ['digest', 'transaction', 'effects', 'events', 'timestamp'],44},45};4647// Make the call48client.GetTransaction(request, metadata, (err: any, response: any) => {49if (err) {50console.error('Error:', err);51} else {52console.log('Response:', JSON.stringify(response, null, 2));53}54});55
1import * as grpc from '@grpc/grpc-js';2import * as protoLoader from '@grpc/proto-loader';3import * as path from 'path';45// Path to the proto file6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');78// Load the proto definition9const packageDefinition = protoLoader.loadSync(PROTO_PATH, {10keepCase: true,11longs: String,12enums: String,13defaults: true,14oneofs: true,15includeDirs: [path.join(__dirname, 'protos/proto')],16});1718const proto = grpc.loadPackageDefinition(packageDefinition) as any;19const LedgerService = proto.sui.rpc.v2.LedgerService;2021// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token22// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678923// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}24// token will be : abcde1234567892526const endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';27const token = 'abcde123456789';2829// Create client with TLS30const client = new LedgerService(endpoint, grpc.credentials.createSsl());3132// Prepare metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Replace this with your actual transaction digest37const txDigest = 'HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G';3839// Prepare request40const request = {41digest: txDigest,42read_mask: {43paths: ['digest', 'transaction', 'effects', 'events', 'timestamp'],44},45};4647// Make the call48client.GetTransaction(request, metadata, (err: any, response: any) => {49if (err) {50console.error('Error:', err);51} else {52console.log('Response:', JSON.stringify(response, null, 2));53}54});55
1import grpc2import json3from google.protobuf.field_mask_pb2 import FieldMask4from google.protobuf.json_format import MessageToDict5from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc678def get_transaction():9# Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token10# For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678911# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}12# token will be: abcde1234567891314endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';15token = 'abcde123456789';1617channel = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())18stub = ledger_service_pb2_grpc.LedgerServiceStub(channel)1920# Specify the transaction digest you want to retrieve21# Replace with an actual Sui transaction digest22tx_digest = "HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G"2324# Create a field mask to specify which fields to include in the response25read_mask = FieldMask(paths=[26"digest",27"transaction",28"effects",29"events",30"timestamp"31])3233# Prepare the GetTransactionRequest34request = ledger_service_pb2.GetTransactionRequest(35digest=tx_digest,36read_mask=read_mask37)3839metadata = [("x-token", token)]4041return stub.GetTransaction(request, metadata=metadata)424344def parse_response_to_json(response):45return json.dumps(46MessageToDict(response, preserving_proto_field_name=True),47indent=248)495051def main():52try:53response = get_transaction()54print(parse_response_to_json(response))55except grpc.RpcError as e:56print(f"{e.code().name}: {e.details()}")575859if __name__ == "__main__":60main()61
1import grpc2import json3from google.protobuf.field_mask_pb2 import FieldMask4from google.protobuf.json_format import MessageToDict5from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc678def get_transaction():9# Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token10# For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678911# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}12# token will be: abcde1234567891314endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';15token = 'abcde123456789';1617channel = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())18stub = ledger_service_pb2_grpc.LedgerServiceStub(channel)1920# Specify the transaction digest you want to retrieve21# Replace with an actual Sui transaction digest22tx_digest = "HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G"2324# Create a field mask to specify which fields to include in the response25read_mask = FieldMask(paths=[26"digest",27"transaction",28"effects",29"events",30"timestamp"31])3233# Prepare the GetTransactionRequest34request = ledger_service_pb2.GetTransactionRequest(35digest=tx_digest,36read_mask=read_mask37)3839metadata = [("x-token", token)]4041return stub.GetTransaction(request, metadata=metadata)424344def parse_response_to_json(response):45return json.dumps(46MessageToDict(response, preserving_proto_field_name=True),47indent=248)495051def main():52try:53response = get_transaction()54print(parse_response_to_json(response))55except grpc.RpcError as e:56print(f"{e.code().name}: {e.details()}")575859if __name__ == "__main__":60main()61