Tutorial: Simple UDT Script
- CKB dev environment: OffCKB (β₯v0.3.0)
- JavaScript SDK: CCC (β₯v0.1.0-alpha.4)
User-Defined Token (UDT) is a fungible token standard on CKB blockchain.
In this tutorial, we will create a UDT Script, a simplified version of XUDT standard to help you better understand how fungible tokens work on CKB.
It is highly recommended to go through the dApp tutorial Create a Fungible Token first before writing your own UDT Script.
The full code of the UDT Script in this tutorial can be found at Github.
Data Structure for simple UDT Cellβ
data:
<amount: uint128>
type:
code_hash: UDT type script hash
args: <owner lock script hash>
lock: <user_defined>
Here the issuer's Lock Script Hash
works like the unique ID for the custom token.
Different Lock Script Hashes correspond to different types of token issued by different owners.
This hash is also used to determine if a transaction is initiated by the token issuer or a regular token holder, to apply different security checks.
- Token Owner: Can perform any operation.
- Regular Holders: The UDT Script ensures that the amount in the output Cells does not exceed that in the input Cells. For a more detailed explanation, please refer to Create a Fungible Token or RFC0025: Simple UDT
Now, let's create a new project to build the UDT Script. We will use OFFCKB and ckb-script-templates.
Initialize a Script Projectβ
Let's run the command to generate a new Script project called sudt-script
(short for simple UDT):
- Command
- Response
offckb create --script sudt-script
β οΈ Favorite `gh:cryptape/ckb-script-templates` not found in config, using it as a git repository: https://github.com/cryptape/ckb-script-templates.git
π€· Project Name: sudt-script
π§ Destination: /tmp/sudt-script ...
π§ project-name: sudt-script ...
π§ Generating template ...
π§ Moving generated files into: `/tmp/sudt-script`...
π§ Initializing a fresh Git repository
β¨ Done! New project created /tmp/sudt-script
Create a New Scriptβ
Letβs create a new Script called sudt
inside the project.
- Command
- Response
cd sudt-script
make generate
π€· Project Name: sudt
π§ Destination: /tmp/sudt-script/contracts/sudt ...
π§ project-name: sudt ...
π§ Generating template ...