Skip to editor
CellScript
Home
Docs
Playground
Registry
Source
中文
中
Playground
Examples
Protocols
Fungible token
NFT collection
AMM pool
Vesting flow
Token launch
CKB primitives
Multisig wallet
Timelock escrow
Canonical style
Witness source
Delegate verifier
Language patterns
Identity lifecycle
Scoped invariants
Order book
Local registry vectors
Blake2b hash lock
Advanced runtime
Stdlib helpers
CKB TYPE_ID create
Spawn pipeline
Compile
Source
Compile Output
Provenance
Source
Set entry
// Playground teaching note: // Start here: this example shows the Cell lifecycle for a simple token. // Follow the consume/create/destroy lines; they are the core of CellScript. module cellscript::fungible_token const U64_MAX: u64 = 18446744073709551615 resource Token has store, create, consume, replace, burn, relock { amount: u64, symbol: [u8; 8], } resource MintAuthority has store, create, replace { token_symbol: [u8; 8], max_supply: u64, minted: u64, } action mint_with_authority(auth_before: MintAuthority, to: Address, amount: u64) -> (auth_after: MintAuthority, token: Token) { transition auth_before -> auth_after verification require amount <= U64_MAX - auth_before.minted, "mint overflow" require auth_before.minted + amount <= auth_before.max_supply, "exceeds max supply" require auth_after.token_symbol == auth_before.token_symbol require auth_after.max_supply == auth_before.max_supply require auth_after.minted == auth_before.minted + amount create token = Token { amount, symbol: auth_before.token_symbol } with_lock(to) } action transfer_token(token: Token, to: Address) -> next_token: Token { verification consume token create next_token = Token { amount: token.amount, symbol: token.symbol } with_lock(to) } action burn(token: Token) { verification require token.amount > 0, "cannot burn zero" destroy token } action merge(a: Token, b: Token, to: Address) -> merged: Token { verification require a.symbol == b.symbol, "symbol mismatch" require b.amount <= U64_MAX - a.amount, "amount overflow" let total = a.amount + b.amount consume a consume b create merged = Token { amount: total, symbol: a.symbol } with_lock(to) }
Actions
Types
Metadata
Loading compiler…