Skip to main content
All balances and transfers are transparent. Each _balances[id][owner] entry and every transfer write reveals (token id, sender, recipient, amount). Anyone reading the chain can reconstruct holdings of every token type. Use this for game items and other transparent use cases — not for private finance.
Authentication uses witness-derived keypairs. See Access Control for why ownPublicKey() cannot be used here.

The Contract

How It Works

ERC1155 supports many token types in one contract. Each token id has its own balance Map.

Storage layout

  • Outer key: token id (e.g. 1 = Gold, 100 = Legendary Sword).
  • Inner map: per-holder balance for that token id.
This makes lookups O(1) and lets balances of different token types be managed independently.

Mixed token types

  • Fungible: mint(alice, 1, 1000) — 1000 copies of token id 1.
  • Non-Fungible: mint(bob, 100, 1) — single edition of token id 100.
  • Semi-Fungible: mint(carol, 50, 10) — 10 of token id 50.
A common convention is to reserve id ranges (e.g. 1..999 for currency, 1000..9999 for items, 10000+ for legendaries).

Authorization

transfer(fromKey, to, id, value):
  • Either the caller authenticates as fromKey directly, or
  • The caller authenticates as an operator that fromKey has approved via setApprovalForAll.
Note from is a Compact reserved keyword, so the parameter is named fromKey.

Admin mint / burn / URI

mint, adminBurn, and setURI are admin-only. Wrap them in your own business logic for richer policies (per-id supply caps, mint windows, delegated minter roles).

Batch operations

Compact does not yet support dynamic arrays, so ERC1155 batch operations (balanceOfBatch, safeBatchTransferFrom) are not implementable verbatim. For now, callers must invoke single-id operations sequentially.

Self-approval guard

Self-approval is rejected — it’s a no-op (the owner can already move their own tokens) and usually indicates a UI bug.

Try It Yourself

1. Create project structure:
2. Save the contract at contracts/game-items.compact.3. Define your token types and mint policy in a wrapper contract or your DApp. The admin pubkey is the constructor argument.4. Compile:

What’s Next

ERC20 Token

Create fungible tokens

ERC721 NFT

Build non-fungible tokens