SimulateTransaction gRPC Method
Parameters
transaction
object
REQUIRED
Loading...
read_mask
object
Loading...
checks
string
Loading...
do_gas_selection
boolean
Loading...
Returns
transaction
object
Loading...
digest
string
Loading...
transaction
object
Loading...
effects
object
Loading...
events
object
Loading...
timestamp
string
Loading...
outputs
array
Loading...
returnValues
array
Loading...
mutatedByRef
array
Loading...
Request
grpcurl \ -import-path . \ -proto sui/rpc/v2beta2/live_data_service.proto \ -H "x-token: abcde123456789" \ -d '{ "transaction": { "bcs": "BASE64_TX_BYTES", "signatures": [ { "scheme": "ED25519", "signature": "BASE64_SIGNATURE", "public_key": "BASE64_PUBLIC_KEY" } ] }, "read_mask": { "paths": ["transaction.effects", "transaction.events"] }, "checks": "ENABLED", "do_gas_selection": true }' \ docs-demo.sui-mainnet.quiknode.pro:9000 \ sui.rpc.v2beta2.LiveDataService/SimulateTransaction
package main import ( "context" "crypto/tls" "encoding/json" "fmt" "log" "time" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/types/known/fieldmaskpb" pb "sui-grpc/sui/rpc/v2beta2" // Your Generated .pb.go files path ) // QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token // For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde123456789 // endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC} // token will be : abcde123456789 var ( token = "YOUR_TOKEN_NUMBER" endpoint = "YOUR_QN_ENDPOINT:9000" ) // Auth structure for x-token type auth struct { token string } func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) { return map[string]string{"x-token": a.token}, nil } func (a *auth) RequireTransportSecurity() bool { return true } func main() { creds := credentials.NewTLS(&tls.Config{}) opts := []grpc.DialOption{ grpc.WithTransportCredentials(creds), grpc.WithPerRPCCredentials(&auth{token}), } conn, err := grpc.Dial(endpoint, opts...) if err != nil { log.Fatalf("Failed to connect: %v", err) } defer conn.Close() client := pb.NewLiveDataServiceClient(conn) req := &pb.SimulateTransactionRequest{ Transaction: &pb.Transaction{ Bcs: &pb.BcsBytes{ Bytes: []byte("YOUR_BCS_SERIALIZED_TX_BYTES"), // Replace with actual bytes }, }, Signatures: []*pb.Signature{ { Scheme: 0, // ED25519 Signature: []byte("YOUR_SIGNATURE_BYTES"), // Replace with actual bytes PublicKey: []byte("YOUR_PUBLIC_KEY_BYTES"), // Replace with actual bytes }, }, ReadMask: &fieldmaskpb.FieldMask{ Paths: []string{ "effects", "events", }, }, } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() resp, err := client.SimulateTransaction(ctx, req) if err != nil { log.Fatalf("SimulateTransaction failed: %v", err) } // Pretty print the response marshaler := protojson.MarshalOptions{ UseProtoNames: true, EmitUnpopulated: true, Indent: " ", } jsonBytes, err := marshaler.Marshal(resp) if err != nil { log.Fatalf("Failed to marshal: %v", err) } var pretty map[string]interface{} if err := json.Unmarshal(jsonBytes, &pretty); err != nil { log.Fatalf("Failed to parse JSON: %v", err) } out, _ := json.MarshalIndent(pretty, "", " ") fmt.Println(string(out)) }
import * as grpc from '@grpc/grpc-js'; import * as protoLoader from '@grpc/proto-loader'; import * as path from 'path'; // Configuration const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2beta2/live_data_service.proto'); // QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token // For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde123456789 // endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC} // token will be : abcde123456789 const endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000'; const token = 'abcde123456789'; // Load protobuf definitions const packageDefinition = protoLoader.loadSync(PROTO_PATH, { keepCase: true, longs: String, enums: String, defaults: true, oneofs: true, includeDirs: [path.join(__dirname, 'protos/proto')], }); const proto = grpc.loadPackageDefinition(packageDefinition) as any; const LiveDataService = proto.sui.rpc.v2beta2.LiveDataService; // Create secure client const client = new LiveDataService(endpoint, grpc.credentials.createSsl()); // Add token metadata const metadata = new grpc.Metadata(); metadata.add('x-token', token); // Request payload const request = { transaction: { bcs: { bytes: Buffer.from('YOUR_BCS_SERIALIZED_TX_BYTES', 'base64') // Replace with actual bytes } }, signatures: [ { scheme: 0, // Usually 0 = ED25519 signature: Buffer.from('YOUR_SIGNATURE_BYTES', 'base64'), // Replace with actual bytes public_key: Buffer.from('YOUR_PUBLIC_KEY_BYTES', 'base64') // Replace with actual bytes } ], read_mask: { paths: ['effects', 'events'] } }; // Perform gRPC call client.SimulateTransaction(request, metadata, (err: grpc.ServiceError | null, response: any) => { if (err) { console.error('gRPC Error:', { code: err.code, message: err.message, details: err.details, }); } else { console.log('SimulateTransaction Response:'); console.log(JSON.stringify(response, null, 2)); } });
import grpc import json from google.protobuf.field_mask_pb2 import FieldMask from google.protobuf.json_format import MessageToDict from sui.rpc.v2beta2 import live_data_service_pb2, live_data_service_pb2_grpc def simulate_transaction(): # QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token # For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde123456789 # endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC} # token will be: abcde123456789 endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000' token = 'abcde123456789' channel = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials()) stub = live_data_service_pb2_grpc.LiveDataServiceStub(channel) read_mask = FieldMask(paths=[ "effects", "events" ]) request = live_data_service_pb2.SimulateTransactionRequest( transaction=live_data_service_pb2.Transaction( bcs=live_data_service_pb2.BcsBytes( bytes=b"YOUR_BCS_SERIALIZED_TX_BYTES" # Replace with actual bytes ) ), signatures=[ live_data_service_pb2.Signature( scheme=0, # ED25519 signature=b"YOUR_SIGNATURE_BYTES", # Replace with actual bytes public_key=b"YOUR_PUBLIC_KEY_BYTES" # Replace with actual bytes ) ], read_mask=read_mask ) metadata = [("x-token", token)] return stub.SimulateTransaction(request, metadata=metadata) def parse_response_to_json(response): return json.dumps( MessageToDict(response, preserving_proto_field_name=True), indent=2 ) def main(): try: response = simulate_transaction() print(parse_response_to_json(response)) except grpc.RpcError as e: print(f"{e.code().name}: {e.details()}") if __name__ == "__main__": main()
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free