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

LedgerService/GetEpoch - SUI

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

Returns information about a specific epoch — validator committee, reference gas price, beginning and ending checkpoints, and total stake. Pass epoch for a specific epoch number, or omit for the current epoch.

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

Request Fields

Field
Type
Required
Description

epoch

uint64

No

Epoch number; omit for the current epoch

read_mask

FieldMask

No

Field paths — e.g. ["epoch", "reference_gas_price", "validators"]. 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 '{
    "epoch": 1084,
    "read_mask": {
        "paths": [
            "*"
        ]
    }
}' \
  go.getblock.io:443/<ACCESS-TOKEN> \
  sui.rpc.v2.LedgerService/GetEpoch
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 = {
    "epoch": 1084,
    "read_mask": {
        "paths": [
            "*"
        ]
    }
};

client.GetEpoch(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

epoch.epoch

string

Epoch number

epoch.committee.members

repeated ValidatorInfo

Validator committee for this epoch

epoch.reference_gas_price

string

Reference gas price for the epoch (MIST)

epoch.total_stake

string

Total SUI staked across all validators (MIST)

epoch.first_checkpoint

string

First checkpoint sequence number in this epoch

epoch.last_checkpoint

string

Last checkpoint sequence number (may be empty for the current epoch)

epoch.start_timestamp_ms

string

Epoch start timestamp

epoch.protocol_version

string

Protocol version active during this epoch

Use Cases

  • Staking dashboards showing per-epoch validator metrics

  • Tracking reference gas price changes between epochs

  • Validator monitoring across committee rotations

  • Detecting protocol version upgrades

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

Epoch number is above the current epoch, or below the node's earliest retained epoch

SDK Integration

Was this helpful?