Type ID(内置 type)约束Type ID (built-in type) Constraints
来源:nervosnetwork/ckb / script/src/type_id.rs(节点内置,非 RISC-V 合约) · code_hash 0x0000…545950455f4944("TYPE_ID"),hash_type type,主网/测试网相同Source: nervosnetwork/ckb / script/src/type_id.rs (built into the node, not a RISC-V binary) · code_hash 0x0000…545950455f4944 ("TYPE_ID"), hash_type type, same on both networks
0 → 1创建Create
Inputs 输入Inputs
tx.inputs[0]CellInput{ since, previous_output }
// 任意 cellCellInput{ since, previous_output }
// any cell
➜
Outputs 输出Outputs
新 cell(output 序号 i)new cell (output index i)Cell{
type: { codeHash: TYPE_ID, hashType: type,
args: blake2b(inputs[0] ‖ u64le(i)) }
}
args 计算args derivation
CellInput44B
output index8B
- CellInput 44B since u64 ‖ tx_hash 32B ‖ index u32since u64 ‖ tx_hash 32B ‖ index u32 交易第一个输入the tx's first input (-3)
- output index 8B group 第一个输出的序号(u64 LE)index of the group's first output (u64 LE) — (-3)
限制Constraints
- args:: 恰为 32 字节exactly 32 bytes (-1)
- args = blake2b(第一个 CellInput ‖ 输出序号)= blake2b(first CellInput ‖ output index) (-3)
1 → 1更新Update
Inputs 输入Inputs
inputCell{ type: TYPE_ID(id) }
➜
Outputs 输出Outputs
outputCell{ type: TYPE_ID(id), data: 新数据 }Cell{ type: TYPE_ID(id), data: new data }
限制Constraints
- group:: 最多 1 个输入与 1 个输出带同一 type_idat most 1 input and 1 output share the same type_id (-2)
1 → 0销毁Destroy
Inputs 输入Inputs
inputCell{ type: TYPE_ID(id) }
➜
Outputs 输出Outputs
outputs不再含该 type_idno cell with this type_id
限制Constraints
- group:: 至多 1 个输入at most 1 input (-2)
部署与来源Deployments & source 内置built-in
源码source nervosnetwork/ckb@426736a4 · script/src/type_id.rs (default-branch HEAD recorded at backfill 2026-10-21; spec/plugin were written from the default branch shortly before (exact read commit not recorded))
二进制核验binary check 内置built-in no code cell (built into CKB)
| 网络network | code_hash | cell_dep | type_id args | 数据哈希data hash | 部署交易deploy tx |
|---|---|---|---|---|---|
| mainnet | 0x0000000000…455f4944 (type) — CKB 内置,无 code cellbuilt into CKB, no code cell | ||||
| testnet | 0x0000000000…455f4944 (type) — CKB 内置,无 code cellbuilt into CKB, no code cell | ||||
链上数据核对于 on-chain data checked 2026-10-20
错误码:-1 ERROR_ARGS · -2 ERROR_TOO_MANY_CELLS · -3 ERROR_INVALID_INPUT_HASH;消耗固定 1,000,000 cyclesError codes: -1 ERROR_ARGS · -2 ERROR_TOO_MANY_CELLS · -3 ERROR_INVALID_INPUT_HASH; costs a fixed 1,000,000 cycles
合约部署常用 type_id 让 code_hash(hash_type=type)在升级后保持不变Deployments use type_id so the code_hash (hash_type=type) stays stable across upgrades
合约部署常用 type_id 让 code_hash(hash_type=type)在升级后保持不变Deployments use type_id so the code_hash (hash_type=type) stays stable across upgrades