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.
Request Fields
Field
Type
Required
Description
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/GetEpochimport * 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
Response Fields
Field
Type
Description
Use Cases
Error Handling
Status Code
Numeric
Cause
SDK Integration
Was this helpful?