FungibleToken
Generic fungible token contract with mint, burn, and transfer capabilities.
Source
packages/contracts/FungibleToken.compact
Ledgers
| Ledger | Type | Description |
|---|---|---|
total_supply | Counter | Total tokens in circulation |
balances | Map<Bytes, Counter> | Balance per account |
metadata | Map<Bytes, Bytes> | Token metadata (owner, name) |
Metadata Keys
| Key | Description |
|---|---|
0x01 | Owner address (can mint) |
0x02 | Token name |
Circuits
initialize(owner: Bytes, name: Bytes)
Sets the token owner and name. Only the owner can mint new tokens.
mint(caller: Bytes, recipient: Bytes, amount: Counter)
Creates new tokens and assigns them to recipient. Fails if caller is not the owner. Increases total_supply.
burn(caller: Bytes, amount: Counter)
Destroys tokens from the caller's balance. Fails if the caller doesn't have enough balance. Decreases total_supply.
transfer(sender: Bytes, recipient: Bytes, amount: Counter)
Transfers tokens between accounts. Fails if sender doesn't have enough balance.
getTotalSupply(): Counter
Returns the current total supply.
getBalance(account: Bytes): Counter
Returns the balance for a specific account.
getOwner(): Bytes
Returns the token owner address.
getTokenName(): Bytes
Returns the token name.
Usage
This contract serves as the base token for Knight Shield's ecosystem. Any token deployed on Knight Shield (e.g., $CLOAK) uses this contract template.
// Register a deployed token
const registry = new TokenRegistry();
registry.register('CLOAK', deployedAddress, {
rawTokenType: 'fungible_token_v1'
});
// Transfer tokens
const helper = new TransferHelper(wallet, registry);
await helper.sendToken('CLOAK', recipientAddress, 1000n);