SimulateTransaction gRPC Method
參數
transaction
物件
必填
載入中...
read_mask
物件
載入中...
checks
字串
載入中...
do_gas_selection
布林值
載入中...
退貨
transaction
物件
載入中...
digest
字串
載入中...
transaction
物件
載入中...
effects
物件
載入中...
events
物件
載入中...
時間戳記
字串
載入中...
outputs
陣列
載入中...
returnValues
陣列
載入中...
mutatedByRef
陣列
載入中...
請求
1grpcurl \2-import-path . \3-proto sui/rpc/v2/state_service.proto \4-H "x-token: abcde123456789" \5-d '{6"transaction": {7"bcs": "BASE64_TX_BYTES",8"signatures": [9{10"scheme": "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.sui-mainnet.quiknode.pro:9000 \21sui.rpc.v2.StateService/SimulateTransaction
1grpcurl \2-import-path . \3-proto sui/rpc/v2/state_service.proto \4-H "x-token: abcde123456789" \5-d '{6"transaction": {7"bcs": "BASE64_TX_BYTES",8"signatures": [9{10"scheme": "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.sui-mainnet.quiknode.pro:9000 \21sui.rpc.v2.StateService/SimulateTransaction
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"log"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-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-token30類型 auth 結構體 {31代幣 字串32}3334func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字串) (map[字串]字串, 錯誤) {35return map[string]string{"x-token": a.token}, nil36}37func (a *auth) RequireTransportSecurity() bool {38return true39}4041func main() {42creds := credentials.NewTLS(&tls.Config{})43opts := []grpc.DialOption{44grpc.WithTransportCredentials(creds),45grpc.WithPerRPC憑證(&auth{token}),46}4748conn, err := grpc.撥號(endpoint, opts...)49如果 err != nil {50log.Fatalf("Failed to connect: %v", err)51}52延後 延遲連接.關閉()5354client := pb.NewStateServiceClient(conn)5556req := &pb.SimulateTransactionRequest{57Transaction: &pb.Transaction{58Bcs: &pb.BcsBytes{59Bytes: []byte("YOUR_BCS_SERIALIZED_TX_BYTES"), // Replace with actual bytes60},61},62Signatures: []*pb.Signature{63{64Scheme: 0, // ED2551965Signature: []byte("YOUR_SIGNATURE_BYTES"), // Replace with actual bytes66PublicKey: []byte("YOUR_PUBLIC_KEY_BYTES"), // Replace with actual bytes67},68},69ReadMask: &fieldmaskpb.FieldMask{70Paths: []string{71"effects",72"events",73},74},75}7677ctx, 取消 := context.WithTimeout(context.背景(), 10*時間.第二)78延後 延後()7980resp, err := client.SimulateTransaction(ctx, req)81如果 err != nil {82log.Fatalf("SimulateTransaction failed: %v", err)83}8485// Pretty print the response86marshaler := protojson.MarshalOptions{87UseProtoNames: true,88EmitUnpopulated: true,89Indent: " ",90}9192jsonBytes, err := marshaler.Marshal(resp)93如果 err != nil {94log.Fatalf("Failed to marshal: %v", err)95}9697var pretty map[string]interface{}98if err := json.Unmarshal(jsonBytes, &pretty); err != nil {99log.Fatalf("Failed to parse JSON: %v", err)100}101102out, _ := json.MarshalIndent(pretty, "", " ")103fmt.Println(string(out))104}105
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"log"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-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-token30類型 auth 結構體 {31代幣 字串32}3334func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字串) (map[字串]字串, 錯誤) {35return map[string]string{"x-token": a.token}, nil36}37func (a *auth) RequireTransportSecurity() bool {38return true39}4041func main() {42creds := credentials.NewTLS(&tls.Config{})43opts := []grpc.DialOption{44grpc.WithTransportCredentials(creds),45grpc.WithPerRPC憑證(&auth{token}),46}4748conn, err := grpc.撥號(endpoint, opts...)49如果 err != nil {50log.Fatalf("Failed to connect: %v", err)51}52延後 延遲連接.關閉()5354client := pb.NewStateServiceClient(conn)5556req := &pb.SimulateTransactionRequest{57Transaction: &pb.Transaction{58Bcs: &pb.BcsBytes{59Bytes: []byte("YOUR_BCS_SERIALIZED_TX_BYTES"), // Replace with actual bytes60},61},62Signatures: []*pb.Signature{63{64Scheme: 0, // ED2551965Signature: []byte("YOUR_SIGNATURE_BYTES"), // Replace with actual bytes66PublicKey: []byte("YOUR_PUBLIC_KEY_BYTES"), // Replace with actual bytes67},68},69ReadMask: &fieldmaskpb.FieldMask{70Paths: []string{71"effects",72"events",73},74},75}7677ctx, 取消 := context.WithTimeout(context.背景(), 10*時間.第二)78延後 延後()7980resp, err := client.SimulateTransaction(ctx, req)81如果 err != nil {82log.Fatalf("SimulateTransaction failed: %v", err)83}8485// Pretty print the response86marshaler := protojson.MarshalOptions{87UseProtoNames: true,88EmitUnpopulated: true,89Indent: " ",90}9192jsonBytes, err := marshaler.Marshal(resp)93如果 err != nil {94log.Fatalf("Failed to marshal: %v", err)95}9697var pretty map[string]interface{}98if err := json.Unmarshal(jsonBytes, &pretty); err != nil {99log.Fatalf("Failed to parse JSON: %v", err)100}101102out, _ := json.MarshalIndent(pretty, "", " ")103fmt.Println(string(out))104}105
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/state_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 StateService = proto.sui.rpc.v2.StateService;2829// Create secure client30const client = new StateService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Request payload37const request = {38transaction: {39bcs: {40bytes: Buffer.from('YOUR_BCS_SERIALIZED_TX_BYTES', 'base64') // Replace with actual bytes41}42},43signatures: [44{45scheme: 0, // Usually 0 = ED2551946signature: Buffer.from('YOUR_SIGNATURE_BYTES', 'base64'), // Replace with actual bytes47public_key: Buffer.from('YOUR_PUBLIC_KEY_BYTES', 'base64') // Replace with actual bytes48}49],50read_mask: {51paths: ['effects', 'events']52}53};5455// Perform gRPC call56client.SimulateTransaction(request, metadata, (err: grpc.ServiceError | null, response: any) => {57if (err) {58console.error('gRPC Error:', {59code: err.code,60message: err.message,61details: err.details,62});63} else {64console.log('SimulateTransaction Response:');65console.log(JSON.stringify(response, null, 2));66}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/state_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 StateService = proto.sui.rpc.v2.StateService;2829// Create secure client30const client = new StateService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const metadata = new grpc.Metadata();34metadata.add('x-token', token);3536// Request payload37const request = {38transaction: {39bcs: {40bytes: Buffer.from('YOUR_BCS_SERIALIZED_TX_BYTES', 'base64') // Replace with actual bytes41}42},43signatures: [44{45scheme: 0, // Usually 0 = ED2551946signature: Buffer.from('YOUR_SIGNATURE_BYTES', 'base64'), // Replace with actual bytes47public_key: Buffer.from('YOUR_PUBLIC_KEY_BYTES', 'base64') // Replace with actual bytes48}49],50read_mask: {51paths: ['effects', 'events']52}53};5455// Perform gRPC call56client.SimulateTransaction(request, metadata, (err: grpc.ServiceError | null, response: any) => {57if (err) {58console.error('gRPC Error:', {59code: err.code,60message: err.message,61details: err.details,62});63} else {64console.log('SimulateTransaction Response:');65console.log(JSON.stringify(response, null, 2));66}67});68
1import grpc2匯入 json3from google.protobuf.field_mask_pb2 import FieldMask4from google.protobuf.json_format import MessageToDict5from sui.rpc.v2 import state_service_pb2, state_service_pb2_grpc678def simulate_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 = state_service_pb2_grpc.StateServiceStub(channel)1920read_mask = FieldMask(paths=[21"effects",22"events"23])2425request = state_service_pb2.SimulateTransactionRequest(26transaction=state_service_pb2.Transaction(27bcs=state_service_pb2.BcsBytes(28bytes=b"YOUR_BCS_SERIALIZED_TX_BYTES" # Replace with actual bytes29)30),31signatures=[32state_service_pb2.Signature(33scheme=0, # ED2551934signature=b"YOUR_SIGNATURE_BYTES", # Replace with actual bytes35public_key=b"YOUR_PUBLIC_KEY_BYTES" # Replace with actual bytes36)37],38read_mask=read_mask39)4041metadata = [("x-token", token)]4243return stub.SimulateTransaction(request, metadata=metadata)444546def parse_response_to_json(response):47return json.dumps(48MessageToDict(response, preserving_proto_field_name=True),49indent=250)515253def main():54try:55response = simulate_transaction()56print(parse_response_to_json(response))57except grpc.RpcError as e:58print(f"{e.code().name}: {e.details()}")5960if __name__ == "__main__":61main()62
1import grpc2匯入 json3from google.protobuf.field_mask_pb2 import FieldMask4from google.protobuf.json_format import MessageToDict5from sui.rpc.v2 import state_service_pb2, state_service_pb2_grpc678def simulate_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 = state_service_pb2_grpc.StateServiceStub(channel)1920read_mask = FieldMask(paths=[21"effects",22"events"23])2425request = state_service_pb2.SimulateTransactionRequest(26transaction=state_service_pb2.Transaction(27bcs=state_service_pb2.BcsBytes(28bytes=b"YOUR_BCS_SERIALIZED_TX_BYTES" # Replace with actual bytes29)30),31signatures=[32state_service_pb2.Signature(33scheme=0, # ED2551934signature=b"YOUR_SIGNATURE_BYTES", # Replace with actual bytes35public_key=b"YOUR_PUBLIC_KEY_BYTES" # Replace with actual bytes36)37],38read_mask=read_mask39)4041metadata = [("x-token", token)]4243return stub.SimulateTransaction(request, metadata=metadata)444546def parse_response_to_json(response):47return json.dumps(48MessageToDict(response, preserving_proto_field_name=True),49indent=250)515253def main():54try:55response = simulate_transaction()56print(parse_response_to_json(response))57except grpc.RpcError as e:58print(f"{e.code().name}: {e.details()}")5960if __name__ == "__main__":61main()62