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

get_cells_capacity - Nervos

Example code for the get_cells_capacity JSON-RPC method. Complete guide on how to use get_cells_capacity JSON-RPC in GetBlock Web3 documentation.

Returns the total capacity of live cells matching a lock or type script filter. This is the canonical balance query for CKB — pass the lock script for the address and the response is the total CKB balance in Shannon.

Parameters

Parameter
Type
Required
Description

search_key

SearchKey

Yes

Search criteria — script, script_type, optional filter

Request Example

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "get_cells_capacity",
    "params": [
        {
            "script": {
                "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
                "hash_type": "type",
                "args": "0xb39d53656421a3895eb35a627d4a6e76dd4afba6"
            },
            "script_type": "lock"
        }
    ],
    "id": "getblock.io"
}'
import axios from 'axios';

const data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "get_cells_capacity",
    "params": [
        {
            "script": {
                "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
                "hash_type": "type",
                "args": "0xb39d53656421a3895eb35a627d4a6e76dd4afba6"
            },
            "script_type": "lock"
        }
    ],
    "id": "getblock.io"
});

const config = {
    method: 'post',
    url: 'https://go.getblock.io/<ACCESS-TOKEN>/',
    headers: {
        'Content-Type': 'application/json'
    },
    data: data
};

axios(config)
    .then(response => console.log(JSON.stringify(response.data, null, 2)))
    .catch(error => console.log(error));

Response Example

Response Parameters

Field
Type
Description

result.capacity

Uint64

Total capacity of matching live cells in Shannon

result.block_hash

H256

Block hash at which the capacity was computed

result.block_number

Uint64

Block number at which the capacity was computed

Use Cases

  • Wallet balance display (the most common CKB query)

  • Pre-flight funds checks before constructing a transaction

  • Portfolio applications tracking address balances

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

-32601

Method not found

Method does not exist or is not enabled on this node

-32603

Internal error

Server-side error while processing the request

429

Too Many Requests

Rate limit exceeded for your plan

SDK Integration

Was this helpful?