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:
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:

Construct an address from a script

Build an Address directly from a known lock script and a client:
Use fromKnownScript to derive an address from one of the built-in KnownScript entries:

Get an address from a signer

The most common way to obtain an address in a dApp is to ask the connected signer:
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:

Address prefix and network

The prefix tells you which network an address belongs to: The Client exposes addressPrefix so you can read it at runtime:
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.