GetTransaction gRPC Method
参数
摘要
字符串
必填
正在加载...
read_mask
对象
正在加载...
paths
array<string>
正在加载...
退货
交易
对象
正在加载...
摘要
字符串
正在加载...
交易
对象
正在加载...
bcs
对象
正在加载...
名称
字符串
正在加载...
值
字符串
正在加载...
摘要
字符串
正在加载...
版本
整数
正在加载...
kind
对象
正在加载...
programmableTransaction
对象
正在加载...
inputs
数组
正在加载...
kind
字符串
正在加载...
objectId
字符串
正在加载...
版本
字符串
正在加载...
mutable
布尔型
正在加载...
纯粹的
字符串
正在加载...
commands
数组
正在加载...
moveCall
对象
正在加载...
package
字符串
正在加载...
module
字符串
正在加载...
function
字符串
正在加载...
typeArguments
数组
正在加载...
arguments
数组
正在加载...
kind
字符串
正在加载...
输入
整数
正在加载...
结果
整数
正在加载...
发件人
字符串
正在加载...
gasPayment
对象
正在加载...
objects
数组
正在加载...
objectId
字符串
正在加载...
版本
字符串
正在加载...
摘要
字符串
正在加载...
owner
字符串
正在加载...
价格
字符串
正在加载...
budget
字符串
正在加载...
到期
对象
正在加载...
kind
字符串
正在加载...
效果
对象
正在加载...
bcs
对象
正在加载...
名称
字符串
正在加载...
值
字符串
正在加载...
摘要
字符串
正在加载...
版本
整数
正在加载...
状态
对象
正在加载...
success
布尔型
正在加载...
epoch
字符串
正在加载...
gasUsed
对象
正在加载...
computationCost
字符串
正在加载...
storageCost
字符串
正在加载...
storageRebate
字符串
正在加载...
nonRefundableStorageFee
字符串
正在加载...
transactionDigest
字符串
正在加载...
gasObject
对象
正在加载...
eventsDigest
字符串
正在加载...
dependencies
数组
正在加载...
摘要
字符串
正在加载...
lamportVersion
字符串
正在加载...
changedObjects
数组
正在加载...
unchangedConsensusObjects
数组
正在加载...
unchangedSharedObjects
数组
正在加载...
kind
字符串
正在加载...
objectId
字符串
正在加载...
版本
字符串
正在加载...
摘要
字符串
正在加载...
活动
对象
正在加载...
bcs
对象
正在加载...
名称
字符串
正在加载...
值
字符串
正在加载...
摘要
字符串
正在加载...
活动
数组
正在加载...
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“活动”13]14}15}' \16docs-demo.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“活动”13]14}15}' \16docs-demo.mainnet.quiknode.pro:9000 \17sui.rpc.v2.LedgerService/GetTransaction
1包 main23import (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8“日志”9“时间”1011"google.golang.grpc"12"google.golang.grpc"13"google.golang.org/protobuf/encoding/protojson"14"google.golang.org/protobuf/types/known/fieldmaskpb"1516pb "sui" // 您生成的 .pb.go 文件路径17)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 = "您的令牌编号"26endpoint = "您的QN端点:9000"27)2829// Auth structure for x-token30类型 auth 结构体 {31token 字符串32}3334func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字符串) (map[字符串]字符串, error) {35返回 map[字符串]字符串{36“x-token”: a.令牌,37}, nil38}3940func (a *auth) RequireTransportSecurity() bool {41返回 true42}4344func main() {45// TLS credentials46creds := credentials.NewTLS(&tls.Config{})47opts := []grpc.DialOption{48grpc.WithTransportCredentials(creds),49grpc.WithPerRPCCredentials(&auth{令牌}),50}5152conn, err := grpc.Dial(endpoint, opts...)53如果 err != nil {54log.Fatalf("连接失败:%v", err)55}56推迟 conn.关闭()5758client := pb.NewLedgerServiceClient(conn)5960txDigest := "HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G"6162fieldMask := &fieldmaskpb.FieldMask{63Paths: []string{"events", "effects"},64}6566req := &pb.GetTransactionRequest{67Digest: &txDigest,68ReadMask: fieldMask,69}7071ctx, 取消 := context.带超时(context.Background(), 10*时间.第二次)72推迟 取消()7374resp, err := client.GetTransaction(ctx, req)75如果 err != nil {76log.Fatalf("GetTransaction failed: %v", err)77}7879marshaler := protojson.MarshalOptions{80UseProtoNames: true,81EmitUnpopulated: true,82缩进: " ",83}8485jsonBytes, err := marshaler.Marshal(resp)86如果 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, "", " ")96如果 err != nil {97log.Fatalf("Failed to format JSON: %v", err)98}99100fmt.Println(string(prettyJSONBytes))101}102
1包 main23import (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8“日志”9“时间”1011"google.golang.grpc"12"google.golang.grpc"13"google.golang.org/protobuf/encoding/protojson"14"google.golang.org/protobuf/types/known/fieldmaskpb"1516pb "sui" // 您生成的 .pb.go 文件路径17)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 = "您的令牌编号"26endpoint = "您的QN端点:9000"27)2829// Auth structure for x-token30类型 auth 结构体 {31token 字符串32}3334func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字符串) (map[字符串]字符串, error) {35返回 map[字符串]字符串{36“x-token”: a.令牌,37}, nil38}3940func (a *auth) RequireTransportSecurity() bool {41返回 true42}4344func main() {45// TLS credentials46creds := credentials.NewTLS(&tls.Config{})47opts := []grpc.DialOption{48grpc.WithTransportCredentials(creds),49grpc.WithPerRPCCredentials(&auth{令牌}),50}5152conn, err := grpc.Dial(endpoint, opts...)53如果 err != nil {54log.Fatalf("连接失败:%v", err)55}56推迟 conn.关闭()5758client := pb.NewLedgerServiceClient(conn)5960txDigest := "HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G"6162fieldMask := &fieldmaskpb.FieldMask{63Paths: []string{"events", "effects"},64}6566req := &pb.GetTransactionRequest{67Digest: &txDigest,68ReadMask: fieldMask,69}7071ctx, 取消 := context.带超时(context.Background(), 10*时间.第二次)72推迟 取消()7374resp, err := client.GetTransaction(ctx, req)75如果 err != nil {76log.Fatalf("GetTransaction failed: %v", err)77}7879marshaler := protojson.MarshalOptions{80UseProtoNames: true,81EmitUnpopulated: true,82缩进: " ",83}8485jsonBytes, err := marshaler.Marshal(resp)86如果 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, "", " ")96如果 err != nil {97log.Fatalf("Failed to format JSON: %v", err)98}99100fmt.Println(string(prettyJSONBytes))101}102
1import * 作为 grpc from grpc;2import * 作为 protoLoader from grpc;3import * 作为 路径 from '路径';45// Path to the proto file6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');78// Load the proto definition9const 包定义 = protoLoader.loadSync(PROTO_PATH, {10keepCase: true,11多头: 字符串,12枚举: 字符串,13默认值: true,14oneofs: true,15includeDirs: [路径.join(__dirname, 'protos/proto')],16});1718const proto = grpc.loadPackageDefinition(packageDefinition) 作为 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.mainnet.quiknode.pro:9000';27const 令牌 = 'abcde123456789';2829// Create client with TLS30const client = new LedgerService(endpoint, grpc.credentials.createSsl());3132// Prepare metadata33const 元数据 = new grpc.元数据();34元数据.添加('x-token', token);3536// Replace this with your actual transaction digest37const txDigest = 'HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G';3839// Prepare request40const 请求 = {41digest: txDigest,42read_mask: {43paths: ['digest', 'transaction', 'effects', 'events', 'timestamp'],44},45};4647// Make the call48client.GetTransaction(request, metadata, (err: any, response: any) => {49如果 (err) {50console.error('Error:', err);51} else {52console.log('Response:', JSON.stringify(response, null, 2));53}54});55
1import * 作为 grpc from grpc;2import * 作为 protoLoader from grpc;3import * 作为 路径 from '路径';45// Path to the proto file6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');78// Load the proto definition9const 包定义 = protoLoader.loadSync(PROTO_PATH, {10keepCase: true,11多头: 字符串,12枚举: 字符串,13默认值: true,14oneofs: true,15includeDirs: [路径.join(__dirname, 'protos/proto')],16});1718const proto = grpc.loadPackageDefinition(packageDefinition) 作为 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.mainnet.quiknode.pro:9000';27const 令牌 = 'abcde123456789';2829// Create client with TLS30const client = new LedgerService(endpoint, grpc.credentials.createSsl());3132// Prepare metadata33const 元数据 = new grpc.元数据();34元数据.添加('x-token', token);3536// Replace this with your actual transaction digest37const txDigest = 'HjuLoCGjS4wBC5KfqmExUa7GcF3yzaWRN1YoYpgxQC6G';3839// Prepare request40const 请求 = {41digest: txDigest,42read_mask: {43paths: ['digest', 'transaction', 'effects', 'events', 'timestamp'],44},45};4647// Make the call48client.GetTransaction(request, metadata, (err: any, response: any) => {49如果 (err) {50console.error('Error:', err);51} else {52console.log('Response:', JSON.stringify(response, null, 2));53}54});55
1import grpc2导入 json3来源 谷歌.protobuf.field_mask_pb2 导入 FieldMask4来源 谷歌.protobuf.json_format import MessageToDict5from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc678def get_transaction():9#Quicknode 由两个关键组成部分构成:endpoint 和相应的令牌10# 例如:QNEndpoint:mainnet11# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}12# 令牌将为:abcde1234567891314endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';15token = 'abcde123456789';1617频道 = 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 = 字段掩码(路径=[26"digest",27"transaction",28“效果”,29"events",30"timestamp"31])3233# Prepare the GetTransactionRequest34request = ledger_service_pb2.GetTransactionRequest(35digest=tx_digest,36read_mask=read_mask37)3839元数据 = [("x-token", token)]4041return stub.GetTransaction(request, metadata=metadata)424344def parse_response_to_json(response):45返回 json.dumps(46MessageToDict(response, 保留_proto_字段_名称=True),47缩进=248)495051def main():52试一试:53response = get_transaction()54打印(parse_response_to_json(response))55除了 grpc。RpcError 作为 e:56print(f"{e.code().name}: {e.details()}")575859如果 __name__ == "__main__":60主()61
1import grpc2导入 json3来源 谷歌.protobuf.field_mask_pb2 导入 FieldMask4来源 谷歌.protobuf.json_format import MessageToDict5from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc678def get_transaction():9#Quicknode 由两个关键组成部分构成:endpoint 和相应的令牌10# 例如:QNEndpoint:mainnet11# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}12# 令牌将为:abcde1234567891314endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';15token = 'abcde123456789';1617频道 = 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 = 字段掩码(路径=[26"digest",27"transaction",28“效果”,29"events",30"timestamp"31])3233# Prepare the GetTransactionRequest34request = ledger_service_pb2.GetTransactionRequest(35digest=tx_digest,36read_mask=read_mask37)3839元数据 = [("x-token", token)]4041return stub.GetTransaction(request, metadata=metadata)424344def parse_response_to_json(response):45返回 json.dumps(46MessageToDict(response, 保留_proto_字段_名称=True),47缩进=248)495051def main():52试一试:53response = get_transaction()54打印(parse_response_to_json(response))55除了 grpc。RpcError 作为 e:56print(f"{e.code().name}: {e.details()}")575859如果 __name__ == "__main__":60主()61