CKB Contract Flow

standard-udt sUDT 元数据 Type Script 约束standard-udt sUDT Metadata Type Script Constraints

来源:xcshuan/ckb-standard-udt-contracts @d6e6da0 contracts/sudt-meta/src、lib/script-utils、lib/types · 仓库未公布部署(SUDT_CODE_HASH 为构建期常量)Source: xcshuan/ckb-standard-udt-contracts @d6e6da0 contracts/sudt-meta/src, lib/script-utils, lib/types · no deployment published (SUDT_CODE_HASH is a build-time constant)
Type 脚本Type script代币 / UDTToken / UDT开源Open source社区Community
贡献者:Contributed by @xcshuan @xcshuan

给 AI agent:For AI agents: std_sudt_meta.md · llms.txt

0 → Meta创建元数据(可同时首次铸造)Create metadata (optionally with the initial mint)

Inputs 输入Inputs
inputs[0]任意 cell;决定 type idany cell; determines the type id
Outputs 输出Outputs
元数据 cellmetadata cellCell{ lock: ALWAYS_SUCCESS (data2), type: SUDT_META{ args: type_id }, data: SudtMeta{ config_flags, current_supply, … } }
sUDT(可选)sUDT (optional)Cell{ type: SUDT{ args: meta_type_hash } (data2), data: amount }
元数据 cell data = SudtMeta(molecule table,9 字段)Metadata cell data = SudtMeta (molecule table, 9 fields)
header4 + 9×4 B
config_flags1B
current_supply16B u128 LE
decimals1B
name / symbol / uri / extra_dataBytes × 4
mint_authorityAuthorityOpt
metadata_authorityAuthorityOpt
  • header4 + 9×4 Bmolecule table 头molecule table header结构合法well-formed30 / 40
  • config_flags1Bbit0 = SUPPLY_TRACKED;sUDT 只允许此位bit0 = SUPPLY_TRACKED; sUDT allows only this bit⊆ 0x01⊆ 0x0130 / 40
  • current_supply16B u128 LE跟踪的总供应tracked total supply未跟踪时必须为 0must be 0 when untracked31
  • name / symbol / uri / extra_dataBytes × 4上限 1024 / 128 / 2048 / 16384 Blimits 1024 / 128 / 2048 / 16384 B30 / 40
  • mint_authorityAuthorityOptAuthority{ type 0 InputLock | 1 InputType | 2 OutputType | 3 DynamicLinking | 4 Spawn, script_hash 32B, script: ScriptOpt }Authority{ type 0 InputLock | 1 InputType | 2 OutputType | 3 DynamicLinking | 4 Spawn, script_hash 32B, script: ScriptOpt }0–2 时 script = None;3–4 时 script 的 hash = script_hashscript = None for 0–2; for 3–4 the script hashes to script_hash30 / 40
  • metadata_authorityAuthorityOpt30 / 40
header0x82000000 28000000 29000000 39000000 3a000000 42000000 49000000 4d000000 51000000 82000000
config_flags0x01
current_supply0x0010a5d4e8000000…00 (1 000 000 000 000)
decimals0x08
name / symbol0x0400000054657374 ("Test") ‖ 0x03000000545354 ("TST")
uri / extra_data0x00000000 ‖ 0x00000000
mint_authority0x31000000 10000000 11000000 31000000 00 ‖ abab…ab ‖ (None)
metadata_authority(None, 0 B)
示例为按 metadata.mol 手工编码的 130B 值(tracked、InputLock 授权),非链上数据Example is a hand-encoded 130B value following metadata.mol (tracked, InputLock authority), not on-chain data

限制Constraints

  • args= 32B= 32B20
  • 组group输入、输出各 ≤ 1 个;不能都为空≤ 1 per side; not both empty21 / 20
  • output lockhash_type = data2 且 code_hash = 0x3b521cc4…f7f1(always-success 白名单)hash_type = data2 and code_hash = 0x3b521cc4…f7f1 (always-success whitelist)20
  • SudtMetaMolecule、长度上限、config_flags ⊆ 0x01、Authority 形状Molecule, size limits, config_flags ⊆ 0x01, Authority shape30
  • type idargs = blake2b(inputs[0] ‖ 输出序号 u64 LE)args = blake2b(inputs[0] ‖ output index u64 LE)10
  • current_supplytracked:= 输出中绑定 sUDT 总量;untracked:= 0tracked: = total bound sUDT in outputs; untracked: = 031
  • 授权authority创建不检查任何 authoritycreation checks no authority—

Meta → Meta更新元数据 / 记账铸造与协议销毁Update metadata / account mints and protocol burns

Inputs 输入Inputs
元数据 cellmetadata cellCell{ lock: ALWAYS_SUCCESS (data2), type: SUDT_META{ args: type_id }, data: SudtMeta{ supply, mint_authority, metadata_authority, … } }
授权 + sUDTauthority + sUDT满足 Authority 的 cell;被铸造 / 销毁的 sUDTcells satisfying the Authority; sUDT being minted / burned
Outputs 输出Outputs
元数据 cellmetadata cellCell{ lock: ALWAYS_SUCCESS (data2), type: SUDT_META{ args: type_id }, data: SudtMeta{ supply ± Δ, …changed fields } }
元数据 cell data = SudtMeta(molecule table,9 字段)Metadata cell data = SudtMeta (molecule table, 9 fields)
header4 + 9×4 B
config_flags1B
current_supply16B u128 LE
decimals1B
name / symbol / uri / extra_dataBytes × 4
mint_authorityAuthorityOpt
metadata_authorityAuthorityOpt
  • header4 + 9×4 Bmolecule table 头molecule table header结构合法well-formed30 / 40
  • config_flags1Bbit0 = SUPPLY_TRACKED;sUDT 只允许此位bit0 = SUPPLY_TRACKED; sUDT allows only this bit⊆ 0x01⊆ 0x0130 / 40
  • current_supply16B u128 LE跟踪的总供应tracked total supply未跟踪时必须为 0must be 0 when untracked31
  • name / symbol / uri / extra_dataBytes × 4上限 1024 / 128 / 2048 / 16384 Blimits 1024 / 128 / 2048 / 16384 B30 / 40
  • mint_authorityAuthorityOptAuthority{ type 0 InputLock | 1 InputType | 2 OutputType | 3 DynamicLinking | 4 Spawn, script_hash 32B, script: ScriptOpt }Authority{ type 0 InputLock | 1 InputType | 2 OutputType | 3 DynamicLinking | 4 Spawn, script_hash 32B, script: ScriptOpt }0–2 时 script = None;3–4 时 script 的 hash = script_hashscript = None for 0–2; for 3–4 the script hashes to script_hash30 / 40
  • metadata_authorityAuthorityOpt30 / 40
header0x82000000 28000000 29000000 39000000 3a000000 42000000 49000000 4d000000 51000000 82000000
config_flags0x01
current_supply0x0010a5d4e8000000…00 (1 000 000 000 000)
decimals0x08
name / symbol0x0400000054657374 ("Test") ‖ 0x03000000545354 ("TST")
uri / extra_data0x00000000 ‖ 0x00000000
mint_authority0x31000000 10000000 11000000 31000000 00 ‖ abab…ab ‖ (None)
metadata_authority(None, 0 B)
示例为按 metadata.mol 手工编码的 130B 值(tracked、InputLock 授权),非链上数据Example is a hand-encoded 130B value following metadata.mol (tracked, InputLock authority), not on-chain data

限制Constraints

  • output lockalways-success 白名单always-success whitelist20
  • SudtMeta输入输出都可解析input and output parse30 / 31
  • config_flagsSUPPLY_TRACKED 位不可改SUPPLY_TRACKED bit immutable32
  • current_supplyuntracked:= 0;tracked:= 旧值 + Σ输出 − Σ输入(交易内所有绑定 sUDT)untracked: = 0; tracked: = old + Σout − Σin (all bound sUDT in the tx)31
  • 授权authoritymetadata_authority 通过;缺失或失败时回退 mint_authoritymetadata_authority passes; falls back to mint_authority when missing or failing50 / 51
  • 授权authoritycurrent_supply 或 mint_authority 变化时还需 mint_authoritycurrent_supply or mint_authority changed ⇒ mint_authority also required50 / 51
  • 空操作no-op消费元数据 cell 即使不改字段也需要授权spending the metadata cell needs authority even for a no-op50 / 51

Meta → 0销毁元数据(回收 CKB)Destroy metadata (reclaim CKB)

Inputs 输入Inputs
元数据 cellmetadata cellCell{ lock: ALWAYS_SUCCESS (data2), type: SUDT_META{ args: type_id }, data: SudtMeta{ tracked, current_supply = 0 } }
mint 授权mint authority满足 mint_authority 的 cellcells satisfying mint_authority
Outputs 输出Outputs
无元数据输出no metadata output且没有绑定本元数据的 sUDT 输出and no sUDT outputs bound to it
元数据 cell data = SudtMeta(molecule table,9 字段)Metadata cell data = SudtMeta (molecule table, 9 fields)
header4 + 9×4 B
config_flags1B
current_supply16B u128 LE
decimals1B
name / symbol / uri / extra_dataBytes × 4
mint_authorityAuthorityOpt
metadata_authorityAuthorityOpt
  • header4 + 9×4 Bmolecule table 头molecule table header结构合法well-formed30 / 40
  • config_flags1Bbit0 = SUPPLY_TRACKED;sUDT 只允许此位bit0 = SUPPLY_TRACKED; sUDT allows only this bit⊆ 0x01⊆ 0x0130 / 40
  • current_supply16B u128 LE跟踪的总供应tracked total supply未跟踪时必须为 0must be 0 when untracked31
  • name / symbol / uri / extra_dataBytes × 4上限 1024 / 128 / 2048 / 16384 Blimits 1024 / 128 / 2048 / 16384 B30 / 40
  • mint_authorityAuthorityOptAuthority{ type 0 InputLock | 1 InputType | 2 OutputType | 3 DynamicLinking | 4 Spawn, script_hash 32B, script: ScriptOpt }Authority{ type 0 InputLock | 1 InputType | 2 OutputType | 3 DynamicLinking | 4 Spawn, script_hash 32B, script: ScriptOpt }0–2 时 script = None;3–4 时 script 的 hash = script_hashscript = None for 0–2; for 3–4 the script hashes to script_hash30 / 40
  • metadata_authorityAuthorityOpt30 / 40
header0x82000000 28000000 29000000 39000000 3a000000 42000000 49000000 4d000000 51000000 82000000
config_flags0x01
current_supply0x0010a5d4e8000000…00 (1 000 000 000 000)
decimals0x08
name / symbol0x0400000054657374 ("Test") ‖ 0x03000000545354 ("TST")
uri / extra_data0x00000000 ‖ 0x00000000
mint_authority0x31000000 10000000 11000000 31000000 00 ‖ abab…ab ‖ (None)
metadata_authority(None, 0 B)
示例为按 metadata.mol 手工编码的 130B 值(tracked、InputLock 授权),非链上数据Example is a hand-encoded 130B value following metadata.mol (tracked, InputLock authority), not on-chain data

限制Constraints

  • config_flags必须 trackedmust be tracked31
  • current_supply= 0= 031
  • 输出outputs不得有绑定 sUDT(data2、SUDT_CODE_HASH、args = 本 type hash)no bound sUDT (data2, SUDT_CODE_HASH, args = this type hash)31
  • 授权authoritymint_authority 必须存在且通过mint_authority must exist and pass50 / 51
部署与来源Deployments & source 未核验unverified
源码source
xcshuan/ckb-standard-udt-contracts@d6e6da01 · contracts/sudt-meta/src · lib/script-utils/src/authority.rs · lib/script-utils/src/token.rs · lib/script-utils/src/supply.rs · lib/types/src/metadata · lib/types/src/schemas/metadata.mol (commit read when writing this spec (default-branch HEAD, 2026-05-18). No deployment or code_hash is published (dependent code hashes are injected at build time); checksums.txt lists sha256 of release binaries only.)
二进制核验binary check
未核验unverified no deployment resolved on chain
未在链上找到部署no on-chain deployment resolved
链上数据核对于 on-chain data checked 2026-11-12
错误码(contracts/sudt-meta/src/error.rs):1–9 SysError、10 SysTypeIdError、11 SyscallUnknown、20 InvalidArgs、21 DuplicateMetaCell、30 InvalidMetaData、31 InvalidSupply、32 ImmutableSupplyMode、50 AuthorityMissing、51 AuthorityFailed(UnsupportedAuthorityLocation 也映射到 51)。类型层 InvalidSupply → 31,其他解析错误 → 30。Error codes (contracts/sudt-meta/src/error.rs): 1–9 SysError, 10 SysTypeIdError, 11 SyscallUnknown, 20 InvalidArgs, 21 DuplicateMetaCell, 30 InvalidMetaData, 31 InvalidSupply, 32 ImmutableSupplyMode, 50 AuthorityMissing, 51 AuthorityFailed (UnsupportedAuthorityLocation also maps to 51). Types-layer InvalidSupply → 31, other parse errors → 30.
授权方式:InputLock / InputType = 输入中有该 lock / type hash;OutputType = 输出中有该 type hash;DynamicLinking 调用 udt_authorize;Spawn 退出码 0Authority: InputLock / InputType = an input has that lock / type hash; OutputType = an output has that type hash; DynamicLinking calls udt_authorize; Spawn must exit 0
元数据 cell 的 lock 被限定为 always-success(data2 0x3b521cc4…f7f1,debug 构建另允许 ckb-testtool 的 always-success),所有安全性来自本 type script 与 authority。The metadata cell lock is restricted to always-success (data2 0x3b521cc4…f7f1; debug builds also allow the ckb-testtool always-success), so all safety comes from this type script and its authorities.
部署:仓库未公布 code_hash,SUDT_CODE_HASH 在构建时注入;本页 match 为空、无测试交易。checksums.txt 只有 release 二进制的 sha256。Deployment: no code_hash is published and SUDT_CODE_HASH is injected at build time; match is empty and there is no test tx. checksums.txt only lists sha256 of release binaries.