AbstractCreates an instance of ClientJsonRpc.
The URL of the JSON-RPC server.
Optionalconfig: ClientJsonRpcConfigReadonlyrequestorGet fee rate statistics
Get tip block number
Tip block number
Get tip block header
Get the header of the latest block.
Optionalverbosity: null | numberVerbosity level (0 for hex, 1 for object).
The tip block header.
Get block by block number
The block number.
Optionalverbosity: null | numberresult format which allows 0 and 2. (Optional, the default is 2.)
OptionalwithCycles: null | booleanwhether the return cycles of block transactions. (Optional, default false.)
Block
Get block by block hash
The block hash.
Optionalverbosity: null | numberresult format which allows 0 and 2. (Optional, the default is 2.)
OptionalwithCycles: null | booleanwhether the return cycles of block transactions. (Optional, default false.)
Block
Get header by block number
The block number.
Optionalverbosity: null | numberresult format which allows 0 and 1. (Optional, the default is 1.)
BlockHeader
Get header by block hash
The block hash.
Optionalverbosity: null | numberresult format which allows 0 and 1. (Optional, the default is 1.)
BlockHeader
Estimate cycles of a transaction.
The transaction to estimate.
Consumed cycles
Test a transaction.
The transaction to test.
Optionalvalidator: OutputsValidator"passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
Consumed cycles
Send a transaction to node.
The transaction to send.
Optionalvalidator: null | OutputsValidator"passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
Transaction hash.
Get a transaction from node.
The hash of the transaction.
The transaction with status.
find cells from node.
The search key of cells.
Optionalorder: "asc" | "desc"The order of cells.
Optionallimit: NumLikeThe max return size of cells.
Optionalafter: stringPagination parameter.
The found cells.
find transactions from node.
get cells capacity from node.
The search key of cells.
The sum of cells capacity.
AbstractaddressReturns the URL of the JSON-RPC server.
The URL of the JSON-RPC server.
AbstractgetGet the deployment info for a well-known CKB script. Returns the cell deps and type script info needed to use the script.
The KnownScript enum value.
Script info including cellDeps and type hash.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
// Get xUDT script deployment info
const xudtInfo = await client.getKnownScript(ccc.KnownScript.XUdt);
console.log(`xUDT cellDeps:`, xudtInfo.cellDeps);
// Build an xUDT type script
const xudtType = await ccc.Script.fromKnownScript(
client,
ccc.KnownScript.XUdt,
"0xOWNER_LOCK_HASH...",
);
Get the recommended transaction fee rate based on recent blocks. Returns the median fee rate, clamped between min and max fee rates.
The recommended fee rate in Shannons per KB.
Optionalverbosity: null | numberOptionalwithCycles: null | booleanOptionalverbosity: null | numberOptionalwithCycles: null | booleanOptionalverbosity: null | numberOptionalverbosity: null | numberGet a cell by its out point. The cell will be cached if it is found.
The out point of the cell to get.
The cell if it exists, otherwise undefined.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const cell = await client.getCell({
txHash: "0xTX_HASH...",
index: 0,
});
if (cell) {
console.log(`Capacity: ${ccc.fixedPointToString(cell.cellOutput.capacity)} CKB`);
console.log(`Lock: ${cell.cellOutput.lock.codeHash}`);
console.log(`Data: ${cell.outputData}`);
}
Get a live (unspent) cell by its out point. Unlike getCell(), this verifies the cell is still live on-chain.
The out point of the cell.
OptionalwithData: null | booleanWhether to include cell data.
OptionalincludeTxPool: null | booleanWhether to include cells in the transaction pool.
The live cell, or undefined if spent or not found.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const cell = await client.getCellLive(
{ txHash: "0xTX_HASH...", index: 0 },
true, // include data
true, // include tx pool
);
if (cell) {
console.log("Cell is still live!");
} else {
console.log("Cell has been spent or does not exist.");
}
Find cells with pagination support. Returns one page of results at a time with a cursor for the next page.
The indexer search key.
Optionalorder: "asc" | "desc"Sort order ("asc" or "desc").
Optionallimit: NumLikeMaximum cells per page.
Optionalafter: stringCursor from previous page for pagination.
A page of cells with a cursor for the next page.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const { script: lock } = await ccc.Address.fromString("ckt1q...", client);
// Get first page of cells
const page1 = await client.findCellsPaged({
script: lock,
scriptType: "lock",
}, "asc", 20);
console.log(`Found ${page1.cells.length} cells`);
// Get next page
if (page1.cells.length === 20) {
const page2 = await client.findCellsPaged(
{ script: lock, scriptType: "lock" },
"asc", 20, page1.lastCursor,
);
}
Optionalorder: "asc" | "desc"Find cells by search key designed for collectable cells. The result also includes cached cells, the order param only works for cells fetched from RPC.
The search key.
Optionalorder: "asc" | "desc"A async generator for yielding cells.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const { script: lock } = await ccc.Address.fromString("ckt1q...", client);
// Find all cells owned by a lock script
for await (const cell of client.findCells({
script: lock,
scriptType: "lock",
scriptSearchMode: "exact",
withData: true,
})) {
console.log(`Cell: ${cell.outPoint.txHash}:${cell.outPoint.index}`);
console.log(`Capacity: ${ccc.fixedPointToString(cell.cellOutput.capacity)} CKB`);
}
Find cells by lock script, optionally filtered by type script.
The lock script to search by.
Optionaltype: null | ScriptLikeOptional type script filter.
Whether to include cell data (default: true).
Optionalorder: "asc" | "desc"Sort order by block number ("asc" or "desc").
Page size for each RPC call (default: 10).
An async generator yielding matching cells.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const { script: lock } = await ccc.Address.fromString("ckt1q...", client);
// Find all cells belonging to this address
for await (const cell of client.findCellsByLock(lock)) {
console.log(`${ccc.fixedPointToString(cell.cellOutput.capacity)} CKB`);
}
// Find only xUDT cells belonging to this address
const xudtType = await ccc.Script.fromKnownScript(
client, ccc.KnownScript.XUdt, "0xOWNER_LOCK_HASH...",
);
for await (const cell of client.findCellsByLock(lock, xudtType)) {
console.log(`UDT cell found`);
}
Find cells by type script.
The type script to search by.
Whether to include cell data (default: true).
Optionalorder: "asc" | "desc"Sort order by block number.
Page size for each RPC call (default: 10).
An async generator yielding matching cells.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
// Find all xUDT cells of a specific token
const xudtType = await ccc.Script.fromKnownScript(
client, ccc.KnownScript.XUdt, "0xOWNER_LOCK_HASH...",
);
for await (const cell of client.findCellsByType(xudtType)) {
console.log(`Token cell: ${cell.outPoint.txHash}:${cell.outPoint.index}`);
}
Resolve cell dependency info into concrete CellDep objects. If a CellDepInfo specifies a type script, the actual deployed cell is located on-chain.
One or more CellDepInfo or arrays of CellDepInfo.
Resolved CellDep array ready to be added to a transaction.
Optionalorder: "asc" | "desc"Optionallimit: numberOptionalorder: "asc" | "desc"Optionallimit: numberOptionalorder: "asc" | "desc"Optionallimit: numberFind transactions related to a lock script, optionally filtered by type script.
The lock script to search by.
Optional type script filter.
If true, group results by transaction.
Optionalorder: "asc" | "desc"Sort order by block number.
Optionallimit: numberPage size per RPC call.
An async generator yielding transaction records.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const { script: lock } = await ccc.Address.fromString("ckt1q...", client);
// List all transactions related to an address (grouped)
for await (const txRecord of client.findTransactionsByLock(lock, null, true)) {
console.log(`TX: ${txRecord.txHash}, Block: ${txRecord.blockNumber}`);
}
Find transactions related to a lock script, optionally filtered by type script.
The lock script to search by.
Optionaltype: null | ScriptLikeOptional type script filter.
OptionalgroupByTransaction: null | falseIf true, group results by transaction.
Optionalorder: "asc" | "desc"Sort order by block number.
Optionallimit: numberPage size per RPC call.
An async generator yielding transaction records.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const { script: lock } = await ccc.Address.fromString("ckt1q...", client);
// List all transactions related to an address (grouped)
for await (const txRecord of client.findTransactionsByLock(lock, null, true)) {
console.log(`TX: ${txRecord.txHash}, Block: ${txRecord.blockNumber}`);
}
Find transactions related to a lock script, optionally filtered by type script.
The lock script to search by.
Optionaltype: null | ScriptLikeOptional type script filter.
OptionalgroupByTransaction: null | booleanIf true, group results by transaction.
Optionalorder: "asc" | "desc"Sort order by block number.
Optionallimit: numberPage size per RPC call.
An async generator yielding transaction records.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const { script: lock } = await ccc.Address.fromString("ckt1q...", client);
// List all transactions related to an address (grouped)
for await (const txRecord of client.findTransactionsByLock(lock, null, true)) {
console.log(`TX: ${txRecord.txHash}, Block: ${txRecord.blockNumber}`);
}
Optionalorder: "asc" | "desc"Optionallimit: numberOptionalgroupByTransaction: null | falseOptionalorder: "asc" | "desc"Optionallimit: numberOptionalgroupByTransaction: null | booleanOptionalorder: "asc" | "desc"Optionallimit: numberGet the total CKB balance of a single lock script. Only counts cells with no type script and no data (pure CKB capacity cells).
The lock script to query balance for.
The total capacity in Shannons as a bigint.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const { script: lock } = await ccc.Address.fromString(
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq...",
client,
);
const balance = await client.getBalanceSingle(lock);
console.log(`Balance: ${ccc.fixedPointToString(balance)} CKB`);
Get the total CKB balance across multiple lock scripts. Sums the balance from each lock script.
An array of lock scripts to query.
The combined total capacity in Shannons as a bigint.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const signer = new ccc.SignerCkbPrivateKey(client, "0x...");
await signer.connect();
const locks = await signer.getRecommendedAddressObj()
.then(({ script }) => [script]);
const totalBalance = await client.getBalance(locks);
console.log(`Total: ${ccc.fixedPointToString(totalBalance)} CKB`);
Send a signed transaction to the CKB network. Validates the fee rate against the maximum before sending.
The transaction to send.
Optionalvalidator: OutputsValidatorOptional outputs validator ("passthrough" or "well_known_scripts_only").
Optionaloptions: { maxFeeRate?: NumLike }Optional configuration including maxFeeRate.
The transaction hash.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const signer = new ccc.SignerCkbPrivateKey(client, "0x...");
await signer.connect();
const tx = ccc.Transaction.from({
outputs: [{ capacity: ccc.fixedPointFrom(100), lock: receiverLock }],
});
await tx.completeInputsByCapacity(signer);
await tx.completeFeeBy(signer);
// Usually you call signer.sendTransaction(tx) which signs then sends.
// client.sendTransaction expects an already-signed transaction.
const txHash = await client.sendTransaction(tx);
Get a transaction by its hash, including its status and block info.
The transaction hash to look up.
The transaction response with status, or undefined if not found.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
const txResponse = await client.getTransaction("0xTX_HASH...");
if (txResponse) {
console.log(`Status: ${txResponse.status}`);
console.log(`Block: ${txResponse.blockNumber}`);
console.log(`Outputs: ${txResponse.transaction.outputs.length}`);
}
This method gets specified transaction with its block header (if existed). This is mainly for caching because we need the header to test if we can safely trust the cached tx status.
Wait for a transaction to be confirmed on-chain. Polls the node until the transaction reaches the specified confirmation depth.
The transaction hash to wait for.
Number of block confirmations to wait for (default: 0 = committed).
Maximum wait time in milliseconds (default: 60000).
Polling interval in milliseconds (default: 2000).
The transaction response once confirmed, or throws on timeout.
import { ccc } from "@ckb-ccc/core";
const client = new ccc.ClientPublicTestnet();
// Wait for transaction to be committed (0 confirmations)
const tx = await client.waitTransaction("0xTX_HASH...");
console.log(`Confirmed in block: ${tx?.blockNumber}`);
// Wait for 4 confirmations with 2 minute timeout
const confirmedTx = await client.waitTransaction(
"0xTX_HASH...",
4, // confirmations
120000, // timeout: 2 minutes
);
Get a live cell from node.
The out point of the cell.
OptionalwithData: null | booleanInclude data in the response.
OptionalincludeTxPool: null | booleanInclude cells in the tx pool.
The cell
Builds a sender function for a JSON-RPC method.
The JSON-RPC method.
OptionalinTransformers: (undefined | ((_: any) => unknown))[]An array of input transformers.
OptionaloutTransformer: (_: any) => unknownAn output transformer function.
A function that sends a JSON-RPC request with the given method and transformed parameters.
An abstract class implementing JSON-RPC client functionality for a specific URL and timeout. Provides methods for sending transactions and building JSON-RPC payloads.