GetObject gRPC Method
Parâmetros
object_id
cadeia de caracteres
OBRIGATÓRIO
A carregar...
read_mask
objeto
A carregar...
paths
matriz
A carregar...
versão
cadeia de caracteres
A carregar...
Devoluções
objeto
objeto
A carregar...
bcs
objeto
A carregar...
nome
cadeia de caracteres
A carregar...
valor
cadeia de caracteres
A carregar...
objectId
cadeia de caracteres
A carregar...
versão
cadeia de caracteres
A carregar...
digest
cadeia de caracteres
A carregar...
proprietário
objeto
A carregar...
kind
cadeia de caracteres
A carregar...
versão
cadeia de caracteres
A carregar...
objectType
cadeia de caracteres
A carregar...
hasPublicTransfer
booleano
A carregar...
contents
objeto
A carregar...
nome
cadeia de caracteres
A carregar...
valor
cadeia de caracteres
A carregar...
previousTransaction
cadeia de caracteres
A carregar...
storageRebate
cadeia de caracteres
A carregar...
Pedido
1grpcurl \2-import-path . \3-proto sui/rpc/v2/ledger_service.proto \4-H "x-token: YOUR_TOKEN_VALUE" \5-d '{6"object_id": "0x27c4fdb3b846aa3ae4a65ef5127a309aa3c1f466671471a806d8912a18b253e8",7"version": "561366061",8"read_mask": {9"paths": [10"bcs",11"object_id",12"version",13"digest",14"owner",15"object_type",16"has_public_transfer",17"contents",18"previous_transaction",19"storage_rebate"20]21}22}' \23docs-demo.sui-mainnet.quiknode.pro:9000 \24sui.rpc.v2.LedgerService/GetObject
1grpcurl \2-import-path . \3-proto sui/rpc/v2/ledger_service.proto \4-H "x-token: YOUR_TOKEN_VALUE" \5-d '{6"object_id": "0x27c4fdb3b846aa3ae4a65ef5127a309aa3c1f466671471a806d8912a18b253e8",7"version": "561366061",8"read_mask": {9"paths": [10"bcs",11"object_id",12"version",13"digest",14"owner",15"object_type",16"has_public_transfer",17"contents",18"previous_transaction",19"storage_rebate"20]21}22}' \23docs-demo.sui-mainnet.quiknode.pro:9000 \24sui.rpc.v2.LedgerService/GetObject
1pacote principal23importar (4"contexto"5"crypto/tls"6"encoding/json"7"fmt"8"registo"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-token30tipo auth estrutura {31token string32}3334func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]string, erro) {35return map[string]string{36"x-token": a.token,37}, nil38}3940func (a *auth) RequireTransportSecurity() bool {41return true42}4344func main() {45creds := credentials.NewTLS(&tls.Config{})4647opts := []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)5960objectID := "0x27c4fdb3b846aa3ae4a65ef5127a309aa3c1f466671471a806d8912a18b253e8"61version := uint64(561366061) // Optional: request a specific version of the object62fieldMask := &fieldmaskpb.FieldMask{63Paths: []string{64"bcs",65"object_id",66"version",67"digest",68"owner",69"object_type",70"has_public_transfer",71"contents",72"previous_transaction",73"storage_rebate",74},75}7677req := &pb.GetObjectRequest{78ObjectId: &objectID,79Version: &version,80ReadMask: fieldMask,81}8283ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)84defer cancel()8586resp, err := client.GetObject(ctx, req)87if err != nil {88log.Fatalf("GetObject failed: %v", err)89}9091marshaler := protojson.MarshalOptions{92UseProtoNames: true,93EmitUnpopulated: true,94Indent: " ",95}9697jsonBytes, err := marshaler.Marshal(resp)98if err != nil {99log.Fatalf("Failed to marshal response to JSON: %v", err)100}101102var prettyJSON map[string]interface{}103if err := json.Unmarshal(jsonBytes, &prettyJSON); err != nil {104log.Fatalf("Failed to unmarshal JSON: %v", err)105}106107formatted, err := json.MarshalIndent(prettyJSON, "", " ")108if err != nil {109log.Fatalf("Failed to format JSON: %v", err)110}111112fmt.Println(string(formatted))113}114
1pacote principal23importar (4"contexto"5"crypto/tls"6"encoding/json"7"fmt"8"registo"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-token30tipo auth estrutura {31token string32}3334func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]string, erro) {35return map[string]string{36"x-token": a.token,37}, nil38}3940func (a *auth) RequireTransportSecurity() bool {41return true42}4344func main() {45creds := credentials.NewTLS(&tls.Config{})4647opts := []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)5960objectID := "0x27c4fdb3b846aa3ae4a65ef5127a309aa3c1f466671471a806d8912a18b253e8"61version := uint64(561366061) // Optional: request a specific version of the object62fieldMask := &fieldmaskpb.FieldMask{63Paths: []string{64"bcs",65"object_id",66"version",67"digest",68"owner",69"object_type",70"has_public_transfer",71"contents",72"previous_transaction",73"storage_rebate",74},75}7677req := &pb.GetObjectRequest{78ObjectId: &objectID,79Version: &version,80ReadMask: fieldMask,81}8283ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)84defer cancel()8586resp, err := client.GetObject(ctx, req)87if err != nil {88log.Fatalf("GetObject failed: %v", err)89}9091marshaler := protojson.MarshalOptions{92UseProtoNames: true,93EmitUnpopulated: true,94Indent: " ",95}9697jsonBytes, err := marshaler.Marshal(resp)98if err != nil {99log.Fatalf("Failed to marshal response to JSON: %v", err)100}101102var prettyJSON map[string]interface{}103if err := json.Unmarshal(jsonBytes, &prettyJSON); err != nil {104log.Fatalf("Failed to unmarshal JSON: %v", err)105}106107formatted, err := json.MarshalIndent(prettyJSON, "", " ")108if err != nil {109log.Fatalf("Failed to format JSON: %v", err)110}111112fmt.Println(string(formatted))113}114
1import * as grpc from '@grpc/grpc-js';2import * as protoLoader from '@grpc/proto-loader';3import * as path from 'path';45const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');67// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token8// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde1234567899// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}10// token will be : abcde1234567891112const endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';13const token = 'abcde123456789';1415// Load protobuf definitions16const packageDefinition = protoLoader.loadSync(PROTO_PATH, {17keepCase: true,18longs: String,19enums: String,20defaults: true,21oneofs: true,22includeDirs: [path.join(__dirname, 'protos/proto')],23});24const proto = grpc.loadPackageDefinition(packageDefinition) as any;25const LedgerService = proto.sui.rpc.v2.LedgerService;2627// Create secure client28const client = new LedgerService(endpoint, grpc.credentials.createSsl());2930// Metadata for authentication31const metadata = new grpc.Metadata();32metadata.add('x-token', token);3334// Request setup35const request = {36object_id: '0x27c4fdb3b846aa3ae4a65ef5127a309aa3c1f466671471a806d8912a18b253e8',37version: '561366061', // Optional: request a specific version of the object38read_mask: {39paths: [40'bcs',41'object_id',42'version',43'digest',44'owner',45'object_type',46'has_public_transfer',47'contents',48'previous_transaction',49'storage_rebate',50],51},52};5354// Recursively convert byte arrays to hex55function convertBytesToHex(obj: any): any {56if (Array.isArray(obj)) {57return obj.map(convertBytesToHex);58} else if (obj && typeof obj === 'object') {59const result: any = {};60for (const key of Object.keys(obj)) {61const val = obj[key];62if (Buffer.isBuffer(val) || (Array.isArray(val) && typeof val[0] === 'number')) {63result[key] = Buffer.from(val).toString('hex');64} else {65result[key] = convertBytesToHex(val);66}67}68return result;69}70return obj;71}7273// Invoke GetObject74client.GetObject(request, metadata, (err: grpc.ServiceError | null, response: any) => {75if (err) {76console.error('gRPC Error:', {77code: err.code,78message: err.message,79details: err.details,80});81} else {82const decoded = convertBytesToHex(response);83console.log('GetObject Response:');84console.log(JSON.stringify(decoded, null, 2));85}86});87
1import * as grpc from '@grpc/grpc-js';2import * as protoLoader from '@grpc/proto-loader';3import * as path from 'path';45const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');67// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token8// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde1234567899// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}10// token will be : abcde1234567891112const endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';13const token = 'abcde123456789';1415// Load protobuf definitions16const packageDefinition = protoLoader.loadSync(PROTO_PATH, {17keepCase: true,18longs: String,19enums: String,20defaults: true,21oneofs: true,22includeDirs: [path.join(__dirname, 'protos/proto')],23});24const proto = grpc.loadPackageDefinition(packageDefinition) as any;25const LedgerService = proto.sui.rpc.v2.LedgerService;2627// Create secure client28const client = new LedgerService(endpoint, grpc.credentials.createSsl());2930// Metadata for authentication31const metadata = new grpc.Metadata();32metadata.add('x-token', token);3334// Request setup35const request = {36object_id: '0x27c4fdb3b846aa3ae4a65ef5127a309aa3c1f466671471a806d8912a18b253e8',37version: '561366061', // Optional: request a specific version of the object38read_mask: {39paths: [40'bcs',41'object_id',42'version',43'digest',44'owner',45'object_type',46'has_public_transfer',47'contents',48'previous_transaction',49'storage_rebate',50],51},52};5354// Recursively convert byte arrays to hex55function convertBytesToHex(obj: any): any {56if (Array.isArray(obj)) {57return obj.map(convertBytesToHex);58} else if (obj && typeof obj === 'object') {59const result: any = {};60for (const key of Object.keys(obj)) {61const val = obj[key];62if (Buffer.isBuffer(val) || (Array.isArray(val) && typeof val[0] === 'number')) {63result[key] = Buffer.from(val).toString('hex');64} else {65result[key] = convertBytesToHex(val);66}67}68return result;69}70return obj;71}7273// Invoke GetObject74client.GetObject(request, metadata, (err: grpc.ServiceError | null, response: any) => {75if (err) {76console.error('gRPC Error:', {77code: err.code,78message: err.message,79details: err.details,80});81} else {82const decoded = convertBytesToHex(response);83console.log('GetObject Response:');84console.log(JSON.stringify(decoded, null, 2));85}86});87
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_object():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 object ID you want to retrieve21# Replace with an actual Sui object ID22object_id = "0x27c4fdb3b846aa3ae4a65ef5127a309aa3c1f466671471a806d8912a18b253e8"2324# Create a field mask to specify which fields to include in the response25read_mask = FieldMask(paths=[26"bcs",27"object_id",28"version",29"digest",30"owner",31"object_type",32"has_public_transfer",33"contents",34"previous_transaction",35"storage_rebate"36])3738# Optional: request a specific version of the object39version = 5613660614041# Prepare the GetObjectRequest42request = ledger_service_pb2.GetObjectRequest(43object_id=object_id,44version=version,45read_mask=read_mask46)4748metadata = [("x-token", token)]4950return stub.GetObject(request, metadata=metadata)515253def parse_response_to_json(response):54return json.dumps(55MessageToDict(response, preserving_proto_field_name=True),56indent=257)585960def main():61try:62response = get_object()63print(parse_response_to_json(response))64except grpc.RpcError as e:65print(f"{e.code().name}: {e.details()}")666768if __name__ == "__main__":69main()70
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_object():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 object ID you want to retrieve21# Replace with an actual Sui object ID22object_id = "0x27c4fdb3b846aa3ae4a65ef5127a309aa3c1f466671471a806d8912a18b253e8"2324# Create a field mask to specify which fields to include in the response25read_mask = FieldMask(paths=[26"bcs",27"object_id",28"version",29"digest",30"owner",31"object_type",32"has_public_transfer",33"contents",34"previous_transaction",35"storage_rebate"36])3738# Optional: request a specific version of the object39version = 5613660614041# Prepare the GetObjectRequest42request = ledger_service_pb2.GetObjectRequest(43object_id=object_id,44version=version,45read_mask=read_mask46)4748metadata = [("x-token", token)]4950return stub.GetObject(request, metadata=metadata)515253def parse_response_to_json(response):54return json.dumps(55MessageToDict(response, preserving_proto_field_name=True),56indent=257)585960def main():61try:62response = get_object()63print(parse_response_to_json(response))64except grpc.RpcError as e:65print(f"{e.code().name}: {e.details()}")666768if __name__ == "__main__":69main()70
Ainda não tem uma conta?
Crie o seu ponto de extremidade Quicknode em segundos e comece a desenvolver
Comece gratuitamente