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

get_cells - Nervos

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

Returns live cells matching a lock or type script filter. Paginated. This is the canonical way to enumerate UTXOs for an address — pass the lock script for the address and walk the pages.

Parameters

Parameter
Type
Required
Description

search_key

SearchKey

Yes

Search criteria — script (lock or type), script_type, optional filter, optional script_search_mode

order

string

Yes

asc or desc

limit

Uint32

Yes

Maximum results per page (max 1000)

after

string

No

Cursor from previous response for pagination

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",
    "params": [
        {
            "script": {
                "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
                "hash_type": "type",
                "args": "0xb39d53656421a3895eb35a627d4a6e76dd4afba6"
            },
            "script_type": "lock"
        },
        "asc",
        "0x64"
    ],
    "id": "getblock.io"
}'
import axios from 'axios';

const data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "get_cells",
    "params": [
        {
            "script": {
                "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
                "hash_type": "type",
                "args": "0xb39d53656421a3895eb35a627d4a6e76dd4afba6"
            },
            "script_type": "lock"
        },
        "asc",
        "0x64"
    ],
    "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.objects

array of Cell

Live cells matching the search

result.objects[].out_point

OutPoint

Out point of the cell

result.objects[].output.capacity

Uint64

Cell capacity in Shannon

result.objects[].output.lock

Script

Lock script

result.objects[].output.type

Script or null

Type script or null

result.last_cursor

string

Cursor to pass as after for the next page

Use Cases

  • Wallet UTXO enumeration for address balance display

  • Transaction construction — selecting input cells to spend

  • DEX backends enumerating cells of a specific token type

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?