CCC Docs
    Preparing search index...

    Class ClientPublicTestnet

    An abstract class implementing JSON-RPC client functionality for a specific URL and timeout. Provides methods for sending transactions and building JSON-RPC payloads.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    requestor: RequestorJsonRpc
    getFeeRateStatistics: (
        blockRange?: NumLike,
    ) => Promise<{ mean: bigint; median: bigint }> = ...

    Get fee rate statistics

    Type declaration

      • (blockRange?: NumLike): Promise<{ mean: bigint; median: bigint }>
      • Parameters

        Returns Promise<{ mean: bigint; median: bigint }>

        Fee rate statistics

    getTip: () => Promise<bigint> = ...

    Get tip block number

    Type declaration

      • (): Promise<bigint>
      • Returns Promise<bigint>

        Tip block number

    getTipHeader: (verbosity?: null | number) => Promise<ClientBlockHeader> = ...

    Get tip block header

    Type declaration

      • (verbosity?: null | number): Promise<ClientBlockHeader>
      • Get the header of the latest block.

        Parameters

        • Optionalverbosity: null | number

          Verbosity level (0 for hex, 1 for object).

        Returns Promise<ClientBlockHeader>

        The tip block header.

        import { ccc } from "@ckb-ccc/core";

        const client = new ccc.ClientPublicTestnet();
        const header = await client.getTipHeader();
        console.log(`Block #${header.number}, hash: ${header.hash}`);

    result format which allows 0 and 1. (Optional, the default is 1.)

    BlockHeader

    getBlockByNumberNoCache: (
        blockNumber: NumLike,
        verbosity?: null | number,
        withCycles?: null | boolean,
    ) => Promise<undefined | ClientBlock> = ...

    Get block by block number

    Type declaration

      • (
            blockNumber: NumLike,
            verbosity?: null | number,
            withCycles?: null | boolean,
        ): Promise<undefined | ClientBlock>
      • Parameters

        • blockNumber: NumLike

          The block number.

        • Optionalverbosity: null | number

          result format which allows 0 and 2. (Optional, the default is 2.)

        • OptionalwithCycles: null | boolean

          whether the return cycles of block transactions. (Optional, default false.)

        Returns Promise<undefined | ClientBlock>

        Block

    getBlockByHashNoCache: (
        blockHash: BytesLike,
        verbosity?: null | number,
        withCycles?: null | boolean,
    ) => Promise<undefined | ClientBlock> = ...

    Get block by block hash

    Type declaration

      • (
            blockHash: BytesLike,
            verbosity?: null | number,
            withCycles?: null | boolean,
        ): Promise<undefined | ClientBlock>
      • Parameters

        • blockHash: BytesLike

          The block hash.

        • Optionalverbosity: null | number

          result format which allows 0 and 2. (Optional, the default is 2.)

        • OptionalwithCycles: null | boolean

          whether the return cycles of block transactions. (Optional, default false.)

        Returns Promise<undefined | ClientBlock>

        Block

    getHeaderByNumberNoCache: (
        blockNumber: NumLike,
        verbosity?: null | number,
    ) => Promise<undefined | ClientBlockHeader> = ...

    Get header by block number

    Type declaration

      • (
            blockNumber: NumLike,
            verbosity?: null | number,
        ): Promise<undefined | ClientBlockHeader>
      • Parameters

        • blockNumber: NumLike

          The block number.

        • Optionalverbosity: null | number

          result format which allows 0 and 1. (Optional, the default is 1.)

        Returns Promise<undefined | ClientBlockHeader>

        BlockHeader

    getHeaderByHashNoCache: (
        blockHash: BytesLike,
        verbosity?: null | number,
    ) => Promise<undefined | ClientBlockHeader> = ...

    Get header by block hash

    Type declaration

      • (
            blockHash: BytesLike,
            verbosity?: null | number,
        ): Promise<undefined | ClientBlockHeader>
      • Parameters

        • blockHash: BytesLike

          The block hash.

        • Optionalverbosity: null | number

          result format which allows 0 and 1. (Optional, the default is 1.)

        Returns Promise<undefined | ClientBlockHeader>

        BlockHeader

    estimateCycles: (transaction: TransactionLike) => Promise<bigint> = ...

    Estimate cycles of a transaction.

    Type declaration

      • (transaction: TransactionLike): Promise<bigint>
      • Parameters

        Returns Promise<bigint>

        Consumed cycles

    sendTransactionDry: (
        transaction: TransactionLike,
        validator?: OutputsValidator,
    ) => Promise<bigint> = ...

    Test a transaction.

    Type declaration

      • (transaction: TransactionLike, validator?: OutputsValidator): Promise<bigint>
      • Parameters

        • transaction: TransactionLike

          The transaction to test.

        • Optionalvalidator: OutputsValidator

          "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.

        Returns Promise<bigint>

        Consumed cycles

    sendTransactionNoCache: (
        transaction: TransactionLike,
        validator?: null | OutputsValidator,
    ) => Promise<`0x${string}`> = ...

    Send a transaction to node.

    Type declaration

      • (
            transaction: TransactionLike,
            validator?: null | OutputsValidator,
        ): Promise<`0x${string}`>
      • Parameters

        • transaction: TransactionLike

          The transaction to send.

        • Optionalvalidator: null | OutputsValidator

          "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.

        Returns Promise<`0x${string}`>

        Transaction hash.

    getTransactionNoCache: (
        txHash: BytesLike,
    ) => Promise<undefined | ClientTransactionResponse> = ...

    Get a transaction from node.

    Type declaration

    findCellsPagedNoCache: (
        key: ClientIndexerSearchKeyLike,
        order?: "asc" | "desc",
        limit?: NumLike,
        after?: string,
    ) => Promise<ClientFindCellsResponse> = ...

    find cells from node.

    Type declaration

    findTransactionsPaged: {
        (
            key: Omit<ClientIndexerSearchKeyTransactionLike, "groupByTransaction"> & {
                groupByTransaction: true;
            },
            order?: "asc" | "desc",
            limit?: NumLike,
            after?: string,
        ): Promise<ClientFindTransactionsGroupedResponse>;
        (
            key: Omit<ClientIndexerSearchKeyTransactionLike, "groupByTransaction"> & {
                groupByTransaction?: null | false;
            },
            order?: "asc" | "desc",
            limit?: NumLike,
            after?: string,
        ): Promise<ClientFindTransactionsResponse>;
        (
            key: ClientIndexerSearchKeyTransactionLike,
            order?: "asc" | "desc",
            limit?: NumLike,
            after?: string,
        ): Promise<
            ClientFindTransactionsResponse
            | ClientFindTransactionsGroupedResponse,
        >;
    } = ...

    find transactions from node.

    The search key of transactions.

    The order of transactions.

    The max return size of transactions.

    Pagination parameter.

    The found transactions.

    getCellsCapacity: (key: ClientIndexerSearchKeyLike) => Promise<bigint> = ...

    get cells capacity from node.

    Type declaration

    Accessors

    • get url(): string

      Returns the URL of the JSON-RPC server.

      Returns string

      The URL of the JSON-RPC server.

    Methods

    • Get the recommended transaction fee rate based on recent blocks. Returns the median fee rate, clamped between min and max fee rates.

      Parameters

      • OptionalblockRange: NumLike

        Number of recent blocks to analyze.

      • Optionaloptions: { maxFeeRate?: NumLike }

        Optional max fee rate cap.

      Returns Promise<bigint>

      The recommended fee rate in Shannons per KB.

      import { ccc } from "@ckb-ccc/core";

      const client = new ccc.ClientPublicTestnet();
      const feeRate = await client.getFeeRate();
      console.log(`Current fee rate: ${feeRate} Shannons/KB`);
    • Get a cell by its out point. The cell will be cached if it is found.

      Parameters

      • outPointLike: OutPointLike

        The out point of the cell to get.

      Returns Promise<undefined | Cell>

      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.

      Parameters

      • outPointLike: OutPointLike

        The out point of the cell.

      • OptionalwithData: null | boolean

        Whether to include cell data.

      • OptionalincludeTxPool: null | boolean

        Whether to include cells in the transaction pool.

      Returns Promise<undefined | Cell>

      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.

      Parameters

      • key: ClientIndexerSearchKeyLike

        The indexer search key.

      • Optionalorder: "asc" | "desc"

        Sort order ("asc" or "desc").

      • Optionallimit: NumLike

        Maximum cells per page.

      • Optionalafter: string

        Cursor from previous page for pagination.

      Returns Promise<ClientFindCellsResponse>

      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,
      );
      }
    • 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.

      Parameters

      Returns AsyncGenerator<Cell>

      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.

      Parameters

      • lock: ScriptLike

        The lock script to search by.

      • Optionaltype: null | ScriptLike

        Optional type script filter.

      • withData: boolean = true

        Whether to include cell data (default: true).

      • Optionalorder: "asc" | "desc"

        Sort order by block number ("asc" or "desc").

      • limit: number = 10

        Page size for each RPC call (default: 10).

      Returns AsyncGenerator<Cell>

      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.

      Parameters

      • type: ScriptLike

        The type script to search by.

      • withData: boolean = true

        Whether to include cell data (default: true).

      • Optionalorder: "asc" | "desc"

        Sort order by block number.

      • limit: number = 10

        Page size for each RPC call (default: 10).

      Returns AsyncGenerator<Cell>

      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.

      Parameters

      Returns Promise<CellDep[]>

      Resolved CellDep array ready to be added to a transaction.

      import { ccc } from "@ckb-ccc/core";

      const client = new ccc.ClientPublicTestnet();
      const xudtInfo = await client.getKnownScript(ccc.KnownScript.XUdt);
      const cellDeps = await client.getCellDeps(xudtInfo.cellDeps);
      // cellDeps can be added to a transaction:
      // tx.cellDeps.push(...cellDeps);
    • Parameters

      Returns AsyncGenerator<
          {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              cells: { isInput: boolean; cellIndex: bigint }[];
          },
      >

    • Parameters

      Returns AsyncGenerator<
          {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              isInput: boolean;
              cellIndex: bigint;
          },
      >

    • Parameters

      Returns AsyncGenerator<
          | {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              isInput: boolean;
              cellIndex: bigint;
          }
          | {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              cells: { isInput: boolean; cellIndex: bigint }[];
          },
      >

    • Find transactions related to a lock script, optionally filtered by type script.

      Parameters

      • lock: ScriptLike

        The lock script to search by.

      • type: undefined | null | ScriptLike

        Optional type script filter.

      • groupByTransaction: true

        If true, group results by transaction.

      • Optionalorder: "asc" | "desc"

        Sort order by block number.

      • Optionallimit: number

        Page size per RPC call.

      Returns AsyncGenerator<
          {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              cells: { isInput: boolean; cellIndex: bigint }[];
          },
      >

      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.

      Parameters

      • lock: ScriptLike

        The lock script to search by.

      • Optionaltype: null | ScriptLike

        Optional type script filter.

      • OptionalgroupByTransaction: null | false

        If true, group results by transaction.

      • Optionalorder: "asc" | "desc"

        Sort order by block number.

      • Optionallimit: number

        Page size per RPC call.

      Returns AsyncGenerator<
          {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              isInput: boolean;
              cellIndex: bigint;
          },
      >

      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.

      Parameters

      • lock: ScriptLike

        The lock script to search by.

      • Optionaltype: null | ScriptLike

        Optional type script filter.

      • OptionalgroupByTransaction: null | boolean

        If true, group results by transaction.

      • Optionalorder: "asc" | "desc"

        Sort order by block number.

      • Optionallimit: number

        Page size per RPC call.

      Returns AsyncGenerator<
          | {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              isInput: boolean;
              cellIndex: bigint;
          }
          | {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              cells: { isInput: boolean; cellIndex: bigint }[];
          },
      >

      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}`);
      }
    • Parameters

      • type: ScriptLike
      • groupByTransaction: true
      • Optionalorder: "asc" | "desc"
      • Optionallimit: number

      Returns AsyncGenerator<
          {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              cells: { isInput: boolean; cellIndex: bigint }[];
          },
      >

    • Parameters

      • type: ScriptLike
      • OptionalgroupByTransaction: null | false
      • Optionalorder: "asc" | "desc"
      • Optionallimit: number

      Returns AsyncGenerator<
          {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              isInput: boolean;
              cellIndex: bigint;
          },
      >

    • Parameters

      • type: ScriptLike
      • OptionalgroupByTransaction: null | boolean
      • Optionalorder: "asc" | "desc"
      • Optionallimit: number

      Returns AsyncGenerator<
          | {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              isInput: boolean;
              cellIndex: bigint;
          }
          | {
              txHash: `0x${string}`;
              blockNumber: bigint;
              txIndex: bigint;
              cells: { isInput: boolean; cellIndex: bigint }[];
          },
      >

    • Get the total CKB balance of a single lock script. Only counts cells with no type script and no data (pure CKB capacity cells).

      Parameters

      • lock: ScriptLike

        The lock script to query balance for.

      Returns Promise<bigint>

      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.

      Parameters

      • locks: ScriptLike[]

        An array of lock scripts to query.

      Returns Promise<bigint>

      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.

      Parameters

      • transaction: TransactionLike

        The transaction to send.

      • Optionalvalidator: OutputsValidator

        Optional outputs validator ("passthrough" or "well_known_scripts_only").

      • Optionaloptions: { maxFeeRate?: NumLike }

        Optional configuration including maxFeeRate.

      Returns Promise<`0x${string}`>

      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.

      Parameters

      • txHashLike: BytesLike

        The transaction hash to look up.

      Returns Promise<undefined | ClientTransactionResponse>

      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}`);
      }
    • Wait for a transaction to be confirmed on-chain. Polls the node until the transaction reaches the specified confirmation depth.

      Parameters

      • txHash: BytesLike

        The transaction hash to wait for.

      • confirmations: number = 0

        Number of block confirmations to wait for (default: 0 = committed).

      • timeout: number = 60000

        Maximum wait time in milliseconds (default: 60000).

      • interval: number = 2000

        Polling interval in milliseconds (default: 2000).

      Returns Promise<undefined | ClientTransactionResponse>

      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 the deployment info for a well-known CKB script. Returns the cell deps and type script info needed to use the script.

      Parameters

      Returns Promise<ScriptInfo>

      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 a live cell from node.

      Parameters

      • outPoint: OutPointLike

        The out point of the cell.

      • OptionalwithData: null | boolean

        Include data in the response.

      • OptionalincludeTxPool: null | boolean

        Include cells in the tx pool.

      Returns Promise<undefined | Cell>

      The cell

    • Builds a sender function for a JSON-RPC method.

      Parameters

      • rpcMethod: string

        The JSON-RPC method.

      • OptionalinTransformers: (undefined | ((_: any) => unknown))[]

        An array of input transformers.

      • OptionaloutTransformer: (_: any) => unknown

        An output transformer function.

      Returns (...req: unknown[]) => Promise<unknown>

      A function that sends a JSON-RPC request with the given method and transformed parameters.