Example: Simple UDT Script
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 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
alias create-ckb-scripts="cargo generate gh:cryptape/ckb-script-templates workspace"
create-ckb-scripts
⚠️ 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 ...