@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
- npm
- yarn
- pnpm
Import
@ckb-ccc/udt package re-exports the full ccc namespace and adds ccc.udt.Udt.
Create a Udt instance
InstantiateUdt 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, useccc.Script.fromKnownScript() to resolve the type script automatically:
Transfer tokens
Calludt.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 callingtransfer() the transaction only has the desired outputs. You must add:
- UDT change inputs — cells holding enough of the token to cover the transfer.
- CKB inputs — cells covering the byte cost of all outputs.
- 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.
Query token metadata
For SSRI-compliant UDTs, you can read metadata directly from the chain. Each method returns anExecutorResponse — 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?)
| Parameter | Type | Description |
|---|---|---|
code | ccc.OutPointLike | OutPoint of the cell containing the UDT script code. |
script | ccc.ScriptLike | Type script that uniquely identifies this token. |
config.executor | ssri.Executor | null | Optional SSRI executor for on-chain method calls. |
udt.transfer(signer, transfers, tx?)
| Parameter | Type | Description |
|---|---|---|
signer | ccc.Signer | The account sending the tokens. |
transfers | { to: ScriptLike, amount: NumLike }[] | Array of recipients and amounts. |
tx | ccc.TransactionLike | null | Optional existing transaction to extend. |
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.