For the complete documentation index, see llms.txt. This page is also available as Markdown.

LedgerService/GetObject - SUI

Example code for the LedgerService/GetObject gRPC method. Complete guide on how to use LedgerService/GetObject gRPC method in GetBlock Web3 documentation.

Returns object data by object ID. Sui's object-centric model means everything on-chain — coins, NFTs, package metadata, custom Move types — is queried through this method. Optional version lets you retrieve historical state of a specific object version (subject to node retention policies).

Service: sui.rpc.v2.LedgerService Proto file: sui/rpc/v2/ledger_service.proto Full method path: sui.rpc.v2.LedgerService/GetObject

Request Fields

Field
Type
Required
Description

object_id

ObjectId (string)

Yes

32-byte object ID in hex (0x...)

version

uint64 (optional)

No

Specific object version to query; omit for the latest version

read_mask

FieldMask

No

Field paths to include in the response (e.g. ["object_id", "version", "contents"]). Use ["*"] for all fields

Request Example

# Clone the official proto files first (one-time setup):
#   git clone https://github.com/MystenLabs/sui-apis.git && cd sui-apis

grpcurl \
  -import-path proto \
  -proto sui/rpc/v2/ledger_service.proto \
  -H "x-grpc-web: 1" \
  -d '{
    "object_id": "0xc8ec1d6e3a7e9d2f5a8c3e7b1d4f9a6c2e5b8d3f7a1c4e9b2d4f6a8c0e2f4b6d",
    "read_mask": {
        "paths": [
            "*"
        ]
    }
}' \
  go.getblock.io:443/<ACCESS-TOKEN> \
  sui.rpc.v2.LedgerService/GetObject
import * as grpc from '@grpc/grpc-js';
import * as protoLoader from '@grpc/proto-loader';
import * as path from 'path';

const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');
const ACCESS_TOKEN = '<ACCESS-TOKEN>';

const packageDef = protoLoader.loadSync(PROTO_PATH, {
    includeDirs: [path.join(__dirname, 'protos/proto')],
    keepCase: true, longs: String, enums: String, defaults: true,
});
const proto = grpc.loadPackageDefinition(packageDef) as any;
const ServiceClient = proto.sui.rpc.v2.LedgerService;

const metadata = new grpc.Metadata();
metadata.add('authorization', `Bearer ${ACCESS_TOKEN}`);

const client = new ServiceClient('go.getblock.io:443', grpc.credentials.createSsl());

const request = {
    "object_id": "0xc8ec1d6e3a7e9d2f5a8c3e7b1d4f9a6c2e5b8d3f7a1c4e9b2d4f6a8c0e2f4b6d",
    "read_mask": {
        "paths": [
            "*"
        ]
    }
};

client.GetObject(request, metadata, (err: any, response: any) => {
    if (err) {
        console.error('Error:', err);
        return;
    }
    console.log(JSON.stringify(response, null, 2));
});

Response Example

Responses are encoded in Protocol Buffers binary format on the wire. The example below shows the protobuf JSON encoding for readability.

Response Fields

Field
Type
Description

object.object_id

ObjectId

Echoed object ID

object.version

string

Object version (uint64 as decimal string)

object.digest

string

Object content digest

object.owner

Owner

Ownership info — address_owner, object_owner, shared, or immutable

object.object_type

string

Move type — e.g. 0x2::coin::Coin<0x2::sui::SUI> for SUI coins

object.contents

MoveValue

Decoded Move value of the object

object.previous_transaction

string

Digest of the transaction that last modified this object

object.storage_rebate

string

Storage rebate the owner would receive on deletion (MIST)

Use Cases

  • Reading SUI coin balances from coin objects

  • Inspecting NFT metadata and Move struct contents

  • Verifying object ownership before allowing a transaction

  • Building object detail views in explorers

Error Handling

gRPC uses status codes rather than JSON-RPC numeric error codes. The most relevant for this method:

Status Code
Numeric
Cause

UNAUTHENTICATED

16

Missing or invalid <ACCESS-TOKEN> in the URL path

INVALID_ARGUMENT

3

Request fields are missing, malformed, or fail validation

UNAVAILABLE

14

Node is overloaded or temporarily unable to handle the request — retry with backoff

DEADLINE_EXCEEDED

4

Request did not complete within the timeout window

RESOURCE_EXHAUSTED

8

Rate limit exceeded for your plan

NOT_FOUND

5

No object exists at the requested ID, or the version is beyond what the node has retained

SDK Integration

Was this helpful?