Skip to editor
CellScript
Docs
Playground
Registry
Source
中文
中
Navigate
Home
Docs
Playground
Registry
Source
Preferences
Language
中文
Appearance
Light
examples/token.cell
CKB
Saved locally
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
Pipe cleanup
Guide
Compile
Focus mode
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(input auth_before: MintAuthority, witness to: Address, witness amount: u64, output auth_after: MintAuthority, output token: Token) { transition auth_before -> auth_after; 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(input token: Token, witness to: Address, output next_token: Token) { consume token; create next_token = Token { amount: token.amount, symbol: token.symbol, } with_lock(to) } action burn(input token: Token) { require token.amount > 0, "cannot burn zero"; destroy token; } action merge(input a: Token, input b: Token, witness to: Address, output merged: Token) { 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) }
Cell Flow
Actions
Types
Metadata
Loading compiler…