CKB Contract Flow

M-NFT NFT 约束M-NFT NFT Constraints

来源:nervina-labs/ckb-nft-scripts @b5af002 contracts/nft-type/src/{entry,validator}.rs · mainnet 0x2b24…aec9 / testnet 0xb183…959f (type)Source: nervina-labs/ckb-nft-scripts @b5af002 contracts/nft-type/src/{entry,validator}.rs · mainnet 0x2b24…aec9 / testnet 0xb183…959f (type)
Type 脚本Type scriptNFT / DOBNFT / DOB主网Mainnet测试网Testnet开源Open source社区Community
贡献者:Contributed by @duanyytop @duanyytop

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

0 → n铸造(class 1 → 1)Mint (class 1 → 1)

Inputs 输入Inputs
Class cellCell{ type: CLASS { args: class_args 24B }, data: { issued: a, configure: c } }
Outputs 输出Outputs
Class cellCell{ type: CLASS, data: { issued: b > a } }
NFT cell × (b − a)Cell{ type: { codeHash: NFT_TYPE, hashType: type, args: class_args 24B ‖ token_id u32 BE }, data: version 0 ‖ characteristic 8B ‖ configure = c ‖ state ‖ [extinfo] }
data 字节布局data byte layout
version1B
characteristic8B
configure1B
state1B
extinfo…
  • version1B版本version= 011
  • characteristic8B特征characteristicconfigure bit3 = 0 且未锁定才可改changeable only if configure bit3 = 0 and not locked23 / 39
  • configure1B权限位(1 = 禁止):bit0 claim · bit1 lock · bit2 ext_info · bit3 characteristic · bit4 claim 前转移 · bit5 claim 后转移 · bit6 claim 前销毁 · bit7 claim 后销毁permission bits (1 = forbidden): bit0 claim · bit1 lock · bit2 ext_info · bit3 characteristic · bit4 transfer before claim · bit5 transfer after claim · bit6 destroy before claim · bit7 destroy after claim= class configure;不可变= class configure; immutable22 / 24
  • state1Bbit0 claimed · bit1 lockedbit0 claimed · bit1 locked只能单向置位(除非批准)one-way only (unless approved)25 / 26
  • extinfo…扩展信息extension info只能追加append-only31 / 32 / 37

限制Constraints

  • args恰 28 字节exactly 28 bytes7
  • class输入中该 class cell 恰 1 个;issued 增加exactly 1 input with this class type; its issued increases14 / 15
  • token ids同 class 的 NFT 输出数 = 增量,token id 依次为 [a..b)NFT outputs of this class = the increase, token ids [a..b) in order20 / 21
  • configureNFT configure = 输入 class configureNFT configure = input class configure22

n → n更新 / 转移 / claim / lockUpdate / transfer / claim / lock

Inputs 输入Inputs
NFT cellCell{ lock: A, type: NFT, data: { characteristic, configure, state, extinfo } }
Outputs 输出Outputs
NFT cellCell{ lock: B, type: NFT, data: { … } }

限制Constraints

  • witness对应 WitnessArgs.lock 存在the matching WitnessArgs.lock is present40
  • characteristic / configurecharacteristic 改变需权限且未锁定;configure 不变characteristic change needs permission and no lock; configure unchanged23 / 39 / 24
  • state未批准时:claim 需未锁定且允许;不可取消 claim;lock 需允许;不可解锁without approval: claim needs unlocked + allowed; no un-claim; lock needs permission; no unlock35 / 27 / 25 / 28 / 26
  • locklock 改变 = 转移:需未锁定,且按 claim 状态被 configure 允许lock change = transfer: must be unlocked and allowed by configure for the claim state36 / 29 / 30
  • extinfo允许时只能追加且未锁定;不允许时长度不变if allowed: append-only and unlocked; otherwise length unchanged31 / 32 / 37

n → 0销毁Destroy

Inputs 输入Inputs
NFT cellCell{ type: NFT, data: { state } }
Outputs 输出Outputs
无同 class 的 NFTno NFT of this class—

限制Constraints

  • witness对应 WitnessArgs.lock 存在the matching WitnessArgs.lock is present40
  • state未批准时:未锁定,且按 claim 状态被 configure 允许without approval: unlocked and allowed by configure for the claim state38 / 33 / 34
部署与来源Deployments & source 未核验unverified
源码source
nervina-labs/ckb-nft-scripts@b5af002e · contracts/nft-type/src/entry.rs · contracts/nft-type/src/validator.rs · contracts/script-utils/src/nft.rs · contracts/script-utils/src/class.rs · contracts/script-utils/src/helper.rs · contracts/script-utils/src/error.rs (deployment commit named on the wiki page Lina-Mainnet-deployment; the Aggron testnet deployment commit d0a844def34df6b05b7b8e260a6225a477f1bf39 differs only in helper.rs CLASS_TYPE_CODE_HASH)
二进制核验binary check
未核验unverified no binary or checksum at the recorded commit matched the deployed data hash (reproducible build not attempted)
网络networkcode_hashcell_deptype_id args数据哈希data hash部署交易deploy tx
mainnet0x2b24f0d644ccbdd77bbf86b27c8cca02efa0ad051e447c212636d9ee7acaaec9 type0x5dce8acab1…dc21d471:2 code0xfdf9ff0efa…01a85a3b0xf677aac8b6…2ac350df0x5dce8acab1…dc21d471 #5913754
testnet0xb1837b5ad01a88558731953062d1f5cb547adf89ece01e8934a9f0aeed2d959f type0xf11ccb6079…64a4bd1c:2 code0xc5f646d2c1…47ef55370xcf4b06e9c8…b8f4cab30xf11ccb6079…64a4bd1c #3463076
链上数据核对于 on-chain data checked 2026-11-06
版本:wiki Lina-Mainnet-deployment 写明部署提交 b5af002,Aggron-Testnet-deployment 写明 d0a844d;两者合约代码只差 helper.rs 中 CLASS_TYPE_CODE_HASH 常量(主网 0xd51e…3d9a / 测试网 0x095b…e3fc)。之后的提交只调整目录结构与 capsule 版本。未做可复现构建。Version: the wiki Lina-Mainnet-deployment page names deployment commit b5af002 and Aggron-Testnet-deployment names d0a844d; the contract code differs only in helper.rs CLASS_TYPE_CODE_HASH (mainnet 0xd51e…3d9a / testnet 0x095b…e3fc). Later commits only restructure directories and bump capsule. No reproducible build was attempted.
“批准”(helper.rs):cell_deps[0] 的 lock = inputs[0] 的 lock,且 cell_deps[0] 的 type hash[0..20] = issuer id 或 type = 本 class。批准时跳过 claim / lock 规则和销毁规则。解码器不读取 cell_deps,所以这些规则不满足时显示为“未检查”。"Approval" (helper.rs): cell_deps[0] lock = inputs[0] lock, and cell_deps[0] type hash[0..20] = issuer id or its type = this class. With approval the claim / lock rules and the destroy rules are skipped. The decoder does not load cell_deps, so those rules show as "not checked" when unmet.
按源码原样:configure 不允许 ext_info 时只比较数据长度,等长但内容不同的修改能通过。As written: when configure forbids ext_info, only the data length is compared, so a same-length content change passes.
NFT 合约内置 class type code hash(构建常量),所以主网 / 测试网二进制不同。动作按同一 class 的所有 NFT 计数。The NFT script embeds the class type code hash (a build constant), so the mainnet and testnet binaries differ. The action counts all NFTs of the same class.
规则 40(helper.rs):找到第一个带此 type 的输入,取它的 lock,再找第一个使用该 lock 的输入;该位置的 WitnessArgs.lock 必须存在(witness 缺失或解析失败也算缺失),用于禁止 ACP 这类不签名的 lock 更新 / 销毁。Rule 40 (helper.rs): take the first input with this type, take its lock, find the first input with that lock; the WitnessArgs.lock at that index must be present (a missing or unparsable witness counts as absent). It blocks signature-less locks such as ACP from updating / destroying.
错误码(script-utils/src/error.rs,wiki Error-Codes):1–4 syscall · 5 IssuerDataInvalid · 6 IssuerCellsCountError · 7 TypeArgsInvalid · 8 IssuerClassCountError · 9 IssuerSetCountError · 10 IssuerCellCannotDestroyed · 11 VersionInvalid · 12 ClassDataInvalid · 13 ClassTotalSmallerThanIssued · 14 ClassCellsCountError · 15 ClassIssuedInvalid · 16 ClassImmutableFieldsNotSame · 17 ClassCellCannotDestroyed · 18 ClassIdIncreaseError · 19 NFTDataInvalid · 20 NFTCellsCountError · 21 NFTTokenIdIncreaseError · 22–39 NFT 状态规则 · 40 GroupInputWitnessNoneErrorError codes (script-utils/src/error.rs, wiki Error-Codes): 1–4 syscall · 5 IssuerDataInvalid · 6 IssuerCellsCountError · 7 TypeArgsInvalid · 8 IssuerClassCountError · 9 IssuerSetCountError · 10 IssuerCellCannotDestroyed · 11 VersionInvalid · 12 ClassDataInvalid · 13 ClassTotalSmallerThanIssued · 14 ClassCellsCountError · 15 ClassIssuedInvalid · 16 ClassImmutableFieldsNotSame · 17 ClassCellCannotDestroyed · 18 ClassIdIncreaseError · 19 NFTDataInvalid · 20 NFTCellsCountError · 21 NFTTokenIdIncreaseError · 22–39 NFT state rules · 40 GroupInputWitnessNoneError
2026-11-19 上游审阅(非链上升级声明):官方 wiki 仍固定 Lina=b5af002、Aggron=d0a844d;与 HEAD 的差异为格式/导入整理及 helper 内 CLASS_TYPE_CODE_HASH 从 Lina 改为 Aggron。不能用 Aggron 常量替换主网;维持按网络选择 class hash,数据布局、转换和错误码不变。2026-11-19 upstream review (not an on-chain upgrade claim): Official wiki still pins Lina=b5af002 and Aggron=d0a844d. HEAD differs by formatting/import cleanup and switching helper CLASS_TYPE_CODE_HASH from Lina to Aggron. Do not replace the mainnet constant with Aggron; retain network-specific class hashes, layouts, transitions and errors.