SimulateTransactiongRPC
参数
交易
对象
必填
正在加载...
read_mask
对象
正在加载...
支票
字符串
正在加载...
do_gas_selection
布尔型
正在加载...
退货
交易
对象
正在加载...
摘要
字符串
正在加载...
交易
对象
正在加载...
效果
对象
正在加载...
活动
对象
正在加载...
时间戳
字符串
正在加载...
输出
数组
正在加载...
返回值
数组
正在加载...
mutatedByRef
数组
正在加载...
请求
1grpcurl \2-import-path . \3-protosui.proto \4-H "x-token: abcde123456789" \5-d '{6"transaction": {7"bcs": "BASE64_TX_BYTES",8"签名": [9{10"方案": "ED25519",11"signature": "BASE64_SIGNATURE",12"public_key": "BASE64_PUBLIC_KEY"13}14]15},16"read_mask": { "paths": ["transaction.effects", "transaction.events"] },17"checks": "ENABLED",18"do_gas_selection": true19}' \20docs-demo.mainnet.quiknode.pro:9000 \21sui.rpc.v2.StateService/SimulateTransaction
1grpcurl \2-import-path . \3-protosui.proto \4-H "x-token: abcde123456789" \5-d '{6"transaction": {7"bcs": "BASE64_TX_BYTES",8"签名": [9{10"方案": "ED25519",11"signature": "BASE64_SIGNATURE",12"public_key": "BASE64_PUBLIC_KEY"13}14]15},16"read_mask": { "paths": ["transaction.effects", "transaction.events"] },17"checks": "ENABLED",18"do_gas_selection": true19}' \20docs-demo.mainnet.quiknode.pro:9000 \21sui.rpc.v2.StateService/SimulateTransaction
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) {35return map[string]string{"x-token": a.token}, nil36}37func (a *auth) RequireTransportSecurity() bool {38返回 true39}4041func main() {42creds := credentials.NewTLS(&tls.Config{})43opts := []grpc.DialOption{44grpc.WithTransportCredentials(creds),45grpc.WithPerRPCCredentials(&auth{令牌}),46}4748conn, err := grpc.Dial(endpoint, opts...)49如果 err != nil {50log.Fatalf("连接失败:%v", err)51}52推迟 conn.关闭()5354client := pb.NewStateServiceClient(conn)5556req := &pb.SimulateTransactionRequest{57Transaction: &pb.Transaction{58Bcs: &pb.BcsBytes{59字节: []字节("YOUR_BCS_SERIALIZED_TX_BYTES"), // 替换为实际字节数60},61},62Signatures: []*pb.Signature{63{64方案: 0, // ED2551965签名: []字节("YOUR_SIGNATURE_BYTES"), // 替换为实际的字节66公钥: []字节("您的公钥字节"), // 替换为实际的字节数67},68},69ReadMask: &fieldmaskpb.FieldMask{70Paths: []string{71“效果”,72“活动”,73},74},75}7677ctx, 取消 := context.带超时(context.Background(), 10*时间.第二次)78推迟 取消()7980resp, err := client.SimulateTransaction(ctx, req)81如果 err != nil {82log.Fatalf("SimulateTransaction 失败:%v", err)83}8485// Pretty print the response86marshaler := protojson.MarshalOptions{87UseProtoNames: true,88EmitUnpopulated: true,89缩进: " ",90}9192jsonBytes, err := marshaler.Marshal(resp)93如果 err != nil {94log.Fatalf(“序列化失败:%v”, err)95}9697var pretty map[字符串]接口{}98if err := json.Unmarshal(jsonBytes, &pretty); err != nil {99log.Fatalf(“无法解析 JSON:%v”, err)100}101102out, _ := json.MarshalIndent(pretty, "", " ")103fmt.Println(字符串(out))104}105
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) {35return map[string]string{"x-token": a.token}, nil36}37func (a *auth) RequireTransportSecurity() bool {38返回 true39}4041func main() {42creds := credentials.NewTLS(&tls.Config{})43opts := []grpc.DialOption{44grpc.WithTransportCredentials(creds),45grpc.WithPerRPCCredentials(&auth{令牌}),46}4748conn, err := grpc.Dial(endpoint, opts...)49如果 err != nil {50log.Fatalf("连接失败:%v", err)51}52推迟 conn.关闭()5354client := pb.NewStateServiceClient(conn)5556req := &pb.SimulateTransactionRequest{57Transaction: &pb.Transaction{58Bcs: &pb.BcsBytes{59字节: []字节("YOUR_BCS_SERIALIZED_TX_BYTES"), // 替换为实际字节数60},61},62Signatures: []*pb.Signature{63{64方案: 0, // ED2551965签名: []字节("YOUR_SIGNATURE_BYTES"), // 替换为实际的字节66公钥: []字节("您的公钥字节"), // 替换为实际的字节数67},68},69ReadMask: &fieldmaskpb.FieldMask{70Paths: []string{71“效果”,72“活动”,73},74},75}7677ctx, 取消 := context.带超时(context.Background(), 10*时间.第二次)78推迟 取消()7980resp, err := client.SimulateTransaction(ctx, req)81如果 err != nil {82log.Fatalf("SimulateTransaction 失败:%v", err)83}8485// Pretty print the response86marshaler := protojson.MarshalOptions{87UseProtoNames: true,88EmitUnpopulated: true,89缩进: " ",90}9192jsonBytes, err := marshaler.Marshal(resp)93如果 err != nil {94log.Fatalf(“序列化失败:%v”, err)95}9697var pretty map[字符串]接口{}98if err := json.Unmarshal(jsonBytes, &pretty); err != nil {99log.Fatalf(“无法解析 JSON:%v”, err)100}101102out, _ := json.MarshalIndent(pretty, "", " ")103fmt.Println(字符串(out))104}105
1import * 作为 grpc from grpc;2import * 作为 protoLoader from grpc;3import * 作为 路径 from '路径';45// Configuration6const PROTO_PATH = 路径.join(__dirname, sui.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.mainnet.quiknode.pro:9000';14const 令牌 = 'abcde123456789';1516// Load protobuf definitions17const 包定义 = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19多头: 字符串,20枚举: 字符串,21默认值: true,22oneofs: true,23includeDirs: [路径.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) 作为 any;27const StateService = proto.sui.rpc.v2.StateService;2829// Create secure client30const 客户端 = new StateService(endpoint, grpc.凭据.createSsl());3132// Add token metadata33const 元数据 = new grpc.元数据();34元数据.添加('x-token', token);3536// Request payload37const 请求 = {38transaction: {39bcs: {40字节: 缓冲区.来自('YOUR_BCS_SERIALIZED_TX_BYTES', 'base64') // 替换为实际的字节数41}42},43签名: [44{45方案: 0, // 通常 0 = ED2551946签名: 缓冲区.来源('YOUR_SIGNATURE_BYTES', 'base64'), // 替换为实际字节47公钥: 缓冲区.来自('YOUR_PUBLIC_KEY_BYTES', 'base64') // 替换为实际的字节数组48}49],50read_mask: {51路径: ['effects', 'events']52}53};5455// Perform gRPC call56client.SimulateTransaction(request, metadata, (err: grpc.ServiceError | null, response: any) => {57如果 (err) {58console.error('gRPC Error:', {59代码: err.代码,60消息: err.消息,61详细信息: err.详情,62});63} else {64控制台.日志('SimulateTransaction 响应:');65控制台.日志(JSON.stringify(response, null, 2));66}67});68
1import * 作为 grpc from grpc;2import * 作为 protoLoader from grpc;3import * 作为 路径 from '路径';45// Configuration6const PROTO_PATH = 路径.join(__dirname, sui.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.mainnet.quiknode.pro:9000';14const 令牌 = 'abcde123456789';1516// Load protobuf definitions17const 包定义 = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19多头: 字符串,20枚举: 字符串,21默认值: true,22oneofs: true,23includeDirs: [路径.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) 作为 any;27const StateService = proto.sui.rpc.v2.StateService;2829// Create secure client30const 客户端 = new StateService(endpoint, grpc.凭据.createSsl());3132// Add token metadata33const 元数据 = new grpc.元数据();34元数据.添加('x-token', token);3536// Request payload37const 请求 = {38transaction: {39bcs: {40字节: 缓冲区.来自('YOUR_BCS_SERIALIZED_TX_BYTES', 'base64') // 替换为实际的字节数41}42},43签名: [44{45方案: 0, // 通常 0 = ED2551946签名: 缓冲区.来源('YOUR_SIGNATURE_BYTES', 'base64'), // 替换为实际字节47公钥: 缓冲区.来自('YOUR_PUBLIC_KEY_BYTES', 'base64') // 替换为实际的字节数组48}49],50read_mask: {51路径: ['effects', 'events']52}53};5455// Perform gRPC call56client.SimulateTransaction(request, metadata, (err: grpc.ServiceError | null, response: any) => {57如果 (err) {58console.error('gRPC Error:', {59代码: err.代码,60消息: err.消息,61详细信息: err.详情,62});63} else {64控制台.日志('SimulateTransaction 响应:');65控制台.日志(JSON.stringify(response, null, 2));66}67});68
1import grpc2导入 json3来源 谷歌.protobuf.field_mask_pb2 导入 FieldMask4来源 谷歌.protobuf.json_format import MessageToDict5来自 sui.rpc.v2 import state_service_pb2, state_service_pb2_grpc678def simulate_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.mainnet.quiknode.pro:9000'15token = 'abcde123456789'1617频道 = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())18占位符 = state_service_pb2_grpc.StateServiceStub(channel)1920read_mask = 字段掩码(路径=[21“效果”,22“活动”23])2425请求 = state_service_pb2.模拟事务请求(26交易=state_service_pb2.事务(27bcs=state_service_pb2.BcsBytes(28字节=b"YOUR_BCS_SERIALIZED_TX_BYTES" # 请替换为实际字节数29)30),31签名=[32state_service_pb2.签名(33方案=0, # ED2551934签名=b"您的签名字节", # 请替换为实际的字节数组35公钥=b"您的_公钥_字节" # 请替换为实际的字节数36)37],38read_mask=read_mask39)4041元数据 = [("x-token", token)]4243返回 存根.SimulateTransaction(请求, 元数据=元数据)444546def parse_response_to_json(response):47返回 json.dumps(48MessageToDict(response, 保留_proto_字段_名称=True),49缩进=250)515253def main():54试一试:55回复 = 模拟交易()56打印(parse_response_to_json(response))57除了 grpc。RpcError 作为 e:58print(f"{e.code().name}: {e.details()}")5960如果 __name__ == "__main__":61主()62
1import grpc2导入 json3来源 谷歌.protobuf.field_mask_pb2 导入 FieldMask4来源 谷歌.protobuf.json_format import MessageToDict5来自 sui.rpc.v2 import state_service_pb2, state_service_pb2_grpc678def simulate_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.mainnet.quiknode.pro:9000'15token = 'abcde123456789'1617频道 = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())18占位符 = state_service_pb2_grpc.StateServiceStub(channel)1920read_mask = 字段掩码(路径=[21“效果”,22“活动”23])2425请求 = state_service_pb2.模拟事务请求(26交易=state_service_pb2.事务(27bcs=state_service_pb2.BcsBytes(28字节=b"YOUR_BCS_SERIALIZED_TX_BYTES" # 请替换为实际字节数29)30),31签名=[32state_service_pb2.签名(33方案=0, # ED2551934签名=b"您的签名字节", # 请替换为实际的字节数组35公钥=b"您的_公钥_字节" # 请替换为实际的字节数36)37],38read_mask=read_mask39)4041元数据 = [("x-token", token)]4243返回 存根.SimulateTransaction(请求, 元数据=元数据)444546def parse_response_to_json(response):47返回 json.dumps(48MessageToDict(response, 保留_proto_字段_名称=True),49缩进=250)515253def main():54试一试:55回复 = 模拟交易()56打印(parse_response_to_json(response))57除了 grpc。RpcError 作为 e:58print(f"{e.code().name}: {e.details()}")5960如果 __name__ == "__main__":61主()62