# Example: CX30 (Wizard Template)

**CX30** is the enterprise fungible token: balances, allowances, `transfer` / `approve` / `transferFrom`, with the chain-standard storage keys wallets and the explorer read.

- **Deploy path:** the Green Chain admin wizard (**Tokens -> CX30 Standard / CX30 Enterprise**) renders this `.cxs` from the form and compiles it on **CX3VM** - **CX3WASM** by default, **CX3JS** when selected. A CX3WASM deploy through the API without `sourceCode` (for example `Cx3TokenFactory.deployCX30`) is rendered by the chain's own CX30 template (`renderCxsSource`): balances, allowances and, per the request's flags, owner-only `mint` / `burn` and `pause` / `unpause`.
- **Chain reads:** `name`, `symbol`, `decimals`, `totalSupply`, `balanceOf` and `allowance` are answered from contract state (`totalSupply`, `balances`, `allowances`), so wallets, the explorer and the SDK see the token without extra calls.

Excerpts are cut from the wizard template with its default form values (generated from the WebUI source, compiled on CX3JS and CX3WASM).

## CX30 Standard (Full Source)

```cxs
@CX30
@target(CX3WASM)
@auditable
token CX30Token {
    name = "CX30 Token"
    symbol = "CX30"
    decimals = 18
    totalSupply = 1000000

    owner = sender

    mapping balances: address => uint256
    mapping allowances: address => address => uint256

    event Transfer(from: address, to: address, amount: uint256)
    event Approval(owner: address, spender: address, amount: uint256)
    event Mint(to: address, amount: uint256)
    event Burn(from: address, amount: uint256)

    @view
    balanceOf(account: address) -> uint256 {
        return balances[account]
    }

    @view
    allowance(owner: address, spender: address) -> uint256 {
        return allowances[owner][spender]
    }

    @audit
    transfer(to: address, amount: uint256) -> bool {
        require to != address(0), "zero_address"
        require to != address(this), "token_address"
        require amount > 0, "zero_amount"
        require balances[sender] >= amount, "insufficient_balance"
        require to != sender, "self_transfer"

        balances[sender] -= amount
        balances[to] += amount

        emit Transfer(sender, to, amount)
        return true
    }

    @audit
    approve(spender: address, amount: uint256) -> bool {
        allowances[sender][spender] = amount
        emit Approval(sender, spender, amount)
        return true
    }

    @audit
    increaseAllowance(spender: address, added: uint256) -> bool {
        allowances[sender][spender] += added
        emit Approval(sender, spender, allowances[sender][spender])
        return true
    }

    @audit
    decreaseAllowance(spender: address, subtracted: uint256) -> bool {
        require allowances[sender][spender] >= subtracted, "allowance_below_zero"
        allowances[sender][spender] -= subtracted
        emit Approval(sender, spender, allowances[sender][spender])
        return true
    }

    @audit
    transferFrom(from: address, to: address, amount: uint256) -> bool {
        require to != address(0), "zero_address"
        require to != address(this), "token_address"
        require amount > 0, "zero_amount"
        require balances[from] >= amount, "insufficient_balance"
        require allowances[from][sender] >= amount, "insufficient_allowance"

        balances[from] -= amount
        balances[to] += amount
        allowances[from][sender] -= amount

        emit Transfer(from, to, amount)
        return true
    }
}
```

The initial supply goes to the owner at deploy: the chain seeds `totalSupply` and `balances:<owner>` from the form.

`transfer`, `transferFrom` and `mint` (when the form turns minting on) refuse three things, in both templates:

- the zero address (`zero_address`);
- the token's own address, `address(this)` (`token_address`): no wallet can sign for that address, so tokens sent there could never move again;
- an amount of 0 (`zero_amount`).

`increaseAllowance` / `decreaseAllowance` change an allowance by a delta. `approve` overwrites it, so a spender could use the old and the new allowance.

## CX30 Enterprise (Additions)

The **CX30 Enterprise** form adds pause, a blacklist and admin / minter roles on top of the same storage:

```cxs
    @audit
    transfer(to: address, amount: uint256) -> bool {
        require !paused, "contract_paused"
        require to != address(0), "zero_address"
        require to != address(this), "token_address"
        require amount > 0, "zero_amount"
        require sender == owner || !blacklist[sender], "sender_blacklisted"
        require to == owner || !blacklist[to], "recipient_blacklisted"
        require balances[sender] >= amount, "insufficient_balance"
        
        balances[sender] -= amount
        balances[to] += amount
        
        emit Transfer(sender, to, amount)
        return true
    }

    @onlyAdmin
    @audit
    pause() {
        paused = true
        emit Paused(sender)
    }

    @onlyAdmin
    @audit
    addToBlacklist(account: address) {
        blacklist[account] = true
        emit Blacklisted(account)
    }

    @onlyOwner
    @audit
    addAdmin(account: address) {
        admins[account] = true
        emit AdminAdded(account)
    }

    @onlyOwner
    @audit
    removeMinter(account: address) {
        minters[account] = false
        emit MinterRemoved(account)
    }
```

### CX30 Enterprise function list

| Function | Kind | Who may call |
|----------|------|--------------|
| `balanceOf(account: address) -> uint256` | view | anyone (read) |
| `allowance(owner: address, spender: address) -> uint256` | view | anyone (read) |
| `isAdmin(account: address) -> bool` | view | anyone (read) |
| `isMinter(account: address) -> bool` | view | anyone (read) |
| `isBlacklisted(account: address) -> bool` | view | anyone (read) |
| `transfer(to: address, amount: uint256) -> bool` | tx | anyone |
| `approve(spender: address, amount: uint256) -> bool` | tx | anyone |
| `increaseAllowance(spender: address, added: uint256) -> bool` | tx | anyone |
| `decreaseAllowance(spender: address, subtracted: uint256) -> bool` | tx | anyone |
| `transferFrom(from: address, to: address, amount: uint256) -> bool` | tx | anyone |
| `pause()` | tx | `@onlyAdmin` |
| `unpause()` | tx | `@onlyAdmin` |
| `addToBlacklist(account: address)` | tx | `@onlyAdmin` |
| `removeFromBlacklist(account: address)` | tx | `@onlyAdmin` |
| `addAdmin(account: address)` | tx | `@onlyOwner` |
| `addMinter(account: address)` | tx | `@onlyOwner` |
| `removeAdmin(account: address)` | tx | `@onlyOwner` |
| `removeMinter(account: address)` | tx | `@onlyOwner` |

A role decorator (`@onlyMinter`, `@onlyIssuer`, ...) admits the addresses in that role's mapping and always the owner. "anyone" functions still apply their own `require` checks (pause, blacklist, balances).

## Related

- **Deploy-Time CX3Script** - how wizard parameters become `.cxs`
- **Example: Mint & Burn** - capability decorators
- **Example: Blacklist Pattern** - deny-list pattern
