@ckb-ccc/udt provides the Udt and UdtPausable classes for interacting with CKB User Defined Tokens. It supports both SSRI-compliant UDTs and legacy sUDT/xUDT tokens.
User Defined Tokens (UDT) are CKB’s fungible token standard. A UDT is identified by a type script; the token balance of a cell is stored as a little-endian 128-bit integer in the cell’s data field.
Installation
- npm
- yarn
- pnpm
Udt class
Udt extends ssri.Trait and represents a single deployed UDT contract.
Constructor
Metadata methods
These methods query on-chain token metadata when an SSRI executor is provided. They returnundefined for legacy xUDT tokens.
name
symbol
decimals
icon
Transfer
Send tokens to one or more recipients. Returns a transaction that you must complete and sign.Mint
Mint new tokens to one or more recipients. The calling signer must be the token issuer.completeBy
Complete the UDT inputs and add a change output back to the signer’s recommended lock.completeChangeToLock
LikecompleteBy, but send the UDT change to an explicit lock script instead of the signer’s address.
UdtPausable class
UdtPausable extends Udt and adds the ability to pause and unpause token transfers for specific lock scripts. It requires an SSRI executor and only works with SSRI-compliant UDT contracts that support the UDTPausable interface.
pause
Pause token transfers for the given lock scripts.unpause
Re-enable token transfers for the given lock scripts.isPaused
Check whether specific lock scripts are currently paused.enumeratePaused
List all lock hashes that are currently paused, with optional pagination.Example: transfer UDT tokens
1
Instantiate the token
2
Build the transfer transaction
3
Complete inputs, fees, and send
transfer() and mint() return an ssri.ExecutorResponse. Access the transaction via .res on the response object before completing it.