Skip to main content
A CKB address is a bech32m-encoded string that packages two things:
  1. A lock script — the on-chain predicate that controls who can spend the cells at this address (code hash, hash type, and args).
  2. An address prefixckb for mainnet, ckt for testnet.
Because the lock script is embedded in the address, you can always recover the exact script needed to send funds to an address, even without any additional metadata.

Parse an address string

Use Address.fromString to decode an address into a structured object:
import { ccc } from "@ckb-ccc/ccc";

const client = new ccc.ClientPublicMainnet();
const address = await ccc.Address.fromString(
  "ckb1qzda0cr08m85hc8jlnfp3sdrlalyatuqvqdveld...",
  client,
);

console.log(address.script.codeHash); // lock script code hash
console.log(address.script.hashType); // "type" or "data"
console.log(address.script.args);     // lock script args
console.log(address.prefix);          // "ckb"
fromString validates that the address prefix matches the client’s network. It throws if there is a mismatch (e.g. passing a ckt address to a mainnet client). You can also pass a record of clients when you need to handle both networks in the same code path:
const address = await ccc.Address.fromString(someAddress, {
  ckb: mainnetClient,
  ckt: testnetClient,
});

Construct an address from a script

Build an Address directly from a known lock script and a client:
const address = ccc.Address.fromScript(lockScript, client);
console.log(address.toString()); // "ckb1q..."
Use fromKnownScript to derive an address from one of the built-in KnownScript entries:
const address = await ccc.Address.fromKnownScript(
  client,
  ccc.KnownScript.Secp256k1Blake160,
  "0xpublicKeyHash...",
);

Get an address from a signer

The most common way to obtain an address in a dApp is to ask the connected signer:
// Primary address as a string
const addressStr = await signer.getRecommendedAddress();

// Primary address as an Address object (includes the lock script)
const addressObj = await signer.getRecommendedAddressObj();
const { script: lock } = addressObj;

// All addresses controlled by this signer
const allAddresses = await signer.getAddresses(); // string[]
Use getRecommendedAddressObj when you need the lock script — for example, to set it as the recipient of a transaction output — instead of parsing the address string again with Address.fromString.

Convert an address back to a string

Call toString() on any Address instance to produce the bech32m string:
const str = address.toString(); // "ckb1q..." or "ckt1q..."

Address prefix and network

The prefix tells you which network an address belongs to:
PrefixNetwork
ckbMainnet
cktTestnet
The Client exposes addressPrefix so you can read it at runtime:
const client = new ccc.ClientPublicTestnet();
console.log(client.addressPrefix); // "ckt"
Never mix mainnet and testnet addresses. A ckt address decoded against a mainnet client will throw an error. Always pair your Address.fromString call with the correct client instance.