# LedgerService/GetServiceInfo - SUI

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

Returns general information about the Sui node's current state, including the chain ID, network name (`mainnet`, `testnet`, `devnet`), current epoch, current checkpoint height, and the range of locally available checkpoints. This is the most useful single method for confirming connectivity, sync status, and whether a node serves archival or only recent data.

**Service**: `sui.rpc.v2.LedgerService`\
**Proto file**: [`sui/rpc/v2/ledger_service.proto`](https://github.com/MystenLabs/sui-apis/blob/main/proto/sui/rpc/v2/ledger_service.proto)\
**Full method path**: `sui.rpc.v2.LedgerService/GetServiceInfo`

## Request Fields

* The request message is empty — no fields are required.

## Request Example

#### grpcurl

```bash
# 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 '{}' \
  shared.eu-central-1.getblock.io:443/<ACCESS-TOKEN> \
  sui.rpc.v2.LedgerService/GetServiceInfo
```

#### TypeScript (@grpc/grpc-js)

```typescript
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('shared.eu-central-1.getblock.io:443', grpc.credentials.createSsl());

const request = {};

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

#### Python (grpcio)

```python
# First generate Python stubs from the proto files (one-time setup):
#   pip install grpcio grpcio-tools
#   python -m grpc_tools.protoc -I=proto --python_out=. --grpc_python_out=. \
#       proto/sui/rpc/v2/ledger_service.proto

import grpc
from sui.rpc.v2 import sui_rpc_v2_ledger_service_pb2, sui_rpc_v2_ledger_service_pb2_grpc
from google.protobuf.json_format import ParseDict, MessageToJson

ACCESS_TOKEN = '<ACCESS-TOKEN>'

channel = grpc.secure_channel('shared.eu-central-1.getblock.io:443', grpc.ssl_channel_credentials())
stub = sui_rpc_v2_ledger_service_pb2_grpc.LedgerServiceStub(channel)

metadata = [('authorization', f'Bearer {ACCESS_TOKEN}')]

# Build the request message from a dict via ParseDict for readability
request_data = {}
request = ParseDict(request_data, sui_rpc_v2_ledger_service_pb2.LedgerRequest())
# (Use the appropriate <Method>Request type — adjust as needed for the specific method.)

response = stub.GetServiceInfo(request, metadata=metadata)
print(response)
```

#### Rust (tonic)

```rust
// Add to Cargo.toml:
//   tonic = "0.12"
//   prost = "0.13"
//   tokio = { version = "1", features = ["full"] }
// Plus a build.rs invoking tonic_build on the Sui proto files.

use tonic::{transport::Channel, Request};
use sui_rpc_v2::ledger_service_client::LedgerServiceClient;
// Plus the relevant <Method>Request type import from sui_rpc_v2.

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let channel = Channel::from_static("https://shared.eu-central-1.getblock.io").connect().await?;
    let mut client = LedgerServiceClient::with_interceptor(channel, |mut req: Request<()>| {
        req.metadata_mut().insert("authorization", "Bearer <ACCESS-TOKEN>".parse().unwrap());
        Ok(req)
    });

    let request_json = r#"{}"#;
    let request = Request::new(serde_json::from_str(request_json)?);

    let response = client.get_service_info(request).await?;
    println!("Response: {:?}", response.into_inner());
    Ok(())
}
```

## Response Example

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

```json
{
    "chain_id": "4btiuiMPvEENsttpZC7CZ53DruC3MAgfznDbASZ7DR6S",
    "chain": "mainnet",
    "epoch": "1084",
    "checkpoint_height": "260411497",
    "timestamp": {
        "seconds": "1775050511",
        "nanos": 19000000
    },
    "lowest_available_checkpoint": "259896745",
    "lowest_available_checkpoint_objects": "259896745",
    "server": "sui-node/1.68.1-3c0f387ebb40"
}
```

## Response Fields

| Field | Type | Description |
| --- | --- | --- |
| chain_id | string | Genesis-derived chain identifier; mainnet is `4btiuiMPvEENsttpZC7CZ53DruC3MAgfznDbASZ7DR6S` |
| chain | string | Network name — `mainnet`, `testnet`, or `devnet` |
| epoch | string | Current epoch number (uint64 as decimal string) |
| checkpoint_height | string | Latest executed checkpoint sequence number |
| timestamp | Timestamp | Timestamp of the latest checkpoint — seconds and nanos since Unix epoch |
| lowest_available_checkpoint | string | Lowest checkpoint stored locally — useful for detecting archive vs pruning nodes |
| lowest_available_checkpoint_objects | string | Lowest checkpoint with full object data available |
| server | string | Sui node software version string |

## Use Cases

* Confirming connectivity and network identity (mainnet vs testnet)
* Sync-status monitoring before routing reads
* Detecting archive vs pruning nodes via `lowest_available_checkpoint`
* Single-call health check before launching application workloads

## 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 |

## SDK Integration

#### @mysten/sui (TypeScript)

```typescript
// The Mysten Labs TypeScript SDK provides higher-level wrappers around the
// gRPC API. Use @mysten/sui for typed client access:

import { SuiClient } from '@mysten/sui/client';

const client = new SuiClient({
    url: 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/'
});

// Refer to the @mysten/sui API reference for the typed wrapper of this method;
// raw gRPC call to sui.rpc.v2.LedgerService/GetServiceInfo is available as shown in the
// Request Example tabs above.
```

#### pysui (Python)

```python
# pysui is the community-maintained Python SDK for Sui (Mysten Labs does not
# yet publish an official Python SDK). For raw gRPC access, use grpcio with
# the generated proto stubs as shown in the Request Example tabs above.

from pysui import SuiConfig, SyncClient

config = SuiConfig.user_config(
    rpc_url='https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/'
)
client = SyncClient(config)

# Consult pysui docs for the wrapper of LedgerService.GetServiceInfo.
```
