Skip to main content

FungibleToken

Generic fungible token contract with mint, burn, and transfer capabilities.

Source

packages/contracts/FungibleToken.compact

Ledgers

LedgerTypeDescription
total_supplyCounterTotal tokens in circulation
balancesMap<Bytes, Counter>Balance per account
metadataMap<Bytes, Bytes>Token metadata (owner, name)

Metadata Keys

KeyDescription
0x01Owner address (can mint)
0x02Token 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);