Skip to main content
UDT (User Defined Token) is CKB’s standard for fungible tokens — similar to ERC-20 on Ethereum. The @ckb-ccc/udt package provides a high-level Udt class that handles token transfers, minting, change calculation, and metadata retrieval. The Udt class supports two token standards:
  • SSRI-compliant UDTs — the modern standard with richer on-chain metadata.
  • Legacy xUDT / sUDT — the original CKB token standard, also supported for compatibility.

Installation

Import

The @ckb-ccc/udt package re-exports the full ccc namespace and adds ccc.udt.Udt.

Create a Udt instance

Instantiate Udt with the code cell’s OutPoint and the token’s type Script.
txHash / index point to the cell that contains the UDT script code on-chain — find these values in the token’s documentation or on a CKB explorer. The type script args field uniquely identifies the specific token.

Using a known script (xUDT)

For the standard xUDT script, use ccc.Script.fromKnownScript() to resolve the type script automatically:

Transfer tokens

Call udt.transfer() to produce a transaction that sends tokens to one or more recipients.
transfer() returns an ExecutorResponse wrapping the transaction. Destructure .res to get the Transaction object.

Complete the transaction

After calling transfer() the transaction only has the desired outputs. You must add:
  1. UDT change inputs — cells holding enough of the token to cover the transfer.
  2. CKB inputs — cells covering the byte cost of all outputs.
  3. Fee — the network transaction fee.

Full transfer example

transfer-udt.ts

Mint tokens

udt.mint() works identically to transfer() but creates new tokens rather than moving existing ones. Use it only if the signer has minting authority over the token.
Minting is only permitted by accounts authorized by the token’s type script logic. Calling mint() with an unauthorized signer will produce a transaction that is rejected by the CKB network.

Query token metadata

For SSRI-compliant UDTs, you can read metadata directly from the chain. Each method returns an ExecutorResponse — access the value via .res.
Metadata methods return undefined when the UDT was created without an SSRI executor or the token does not implement the optional metadata methods. Always check for undefined before using the value.

API reference

new ccc.udt.Udt(code, script, config?)

udt.transfer(signer, transfers, tx?)

Returns Promise<ExecutorResponse<ccc.Transaction>>.

udt.mint(signer, mints, tx?)

Same signature as transfer(). Returns a transaction that creates new tokens at the specified outputs.

udt.completeBy(tx, signer)

Scans the signer’s cells for UDT inputs, balances them against the outputs, and adds a change output for any leftover tokens. Returns the updated ccc.Transaction.

udt.name() / symbol() / decimals() / icon()

Query SSRI on-chain metadata. Return Promise<ExecutorResponse<string | ccc.Num | undefined>>.

Next steps

Spore NFTs

Create and manage on-chain NFTs with the Spore Protocol.

Send CKB

Review the transaction building pattern used for plain CKB transfers.