StateService/ListBalances - SUI
Example code for the StateService/ListBalances gRPC method. Complete guide on how to use StateService/ListBalances 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/state_service.proto \
-H "x-grpc-web: 1" \
-d '{
"owner": "0xb871a42470b59c7184033a688f883cf24eb5e66eae1db62319bab27adb30b873",
"page_size": 50
}' \
go.getblock.io:443/<ACCESS-TOKEN> \
sui.rpc.v2.StateService/ListBalancesimport * 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/state_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.StateService;
const metadata = new grpc.Metadata();
metadata.add('authorization', `Bearer ${ACCESS_TOKEN}`);
const client = new ServiceClient('go.getblock.io:443', grpc.credentials.createSsl());
const request = {
"owner": "0xb871a42470b59c7184033a688f883cf24eb5e66eae1db62319bab27adb30b873",
"page_size": 50
};
client.ListBalances(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?