API Reference

FungibleToken

This module provides the full FungibleToken module API.

For an overview of the module, read the FungibleToken guide.

Core

import "./node-modules/@openzeppelin-compact/fungible-token/src/FungibleToken" prefix FungibleToken_;

FungibleToken

View on GitHub

Circuits

initialize #initialize

initialize(name_: Opaque<"string">, symbol_: Opaque<"string">, decimals_: Uint<8>) → []

Initializes the contract by setting the name, symbol, and decimals.

This MUST be called in the implementing contract’s constructor. Failure to do so can lead to an irreparable contract.

Requirements:

  • Contract is not initialized.

Constraints:

  • k=10, rows=71

name #name

name() → Opaque<"string">

Returns the token name.

Requirements:

  • Contract is initialized.

Constraints:

  • k=10, rows=37

symbol #symbol

symbol() → Opaque<"string">

Returns the symbol of the token.

Requirements:

  • Contract is initialized.

Constraints:

  • k=10, rows=37

decimals #decimals

decimals() → Uint<8>

Returns the number of decimals used to get its user representation.

Requirements:

  • Contract is initialized.

Constraints:

  • k=10, rows=36

totalSupply #totalsupply

totalSupply() → Uint<128>

Returns the value of tokens in existence.

Requirements:

  • Contract is initialized.

Constraints:

  • k=10, rows=36

balanceOf #balanceof

balanceOf(account: Either<ZswapCoinPublicKey, ContractAddress>) → Uint<128>

Returns the value of tokens owned by account.

Requirements:

  • Contract is initialized.

Constraints:

  • k=10, rows=310

transfer #transfer

transfer(to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → Boolean

Moves a value amount of tokens from the caller’s account to to.

Transfers to contract addresses are currently disallowed until contract-to-contract interactions are supported in Compact.

This restriction prevents assets from being inadvertently locked in contracts that cannot currently handle token receipt.

Requirements:

  • Contract is initialized.
  • to is not a ContractAddress.
  • to is not the zero address.
  • The caller has a balance of at least value.

Constraints:

  • k=11, rows=1173

_unsafeTransfer #_unsafetransfer

_unsafeTransfer(to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → Boolean

Unsafe variant of transfer which allows transfers to contract addresses.

Transfers to contract addresses are considered unsafe because contract-to-contract calls are not currently supported. Tokens sent to a contract address may become irretrievable.

Once contract-to-contract calls are supported, this circuit may be deprecated.

Requirements:

  • Contract is initialized.
  • to is not the zero address.
  • The caller has a balance of at least value.

Constraints:

  • k=11, rows=1170

allowance #allowance

allowance(owner: Either<ZswapCoinPublicKey, ContractAddress>, spender: Either<ZswapCoinPublicKey, ContractAddress>) → Uint<128>

Returns the remaining number of tokens that spender will be allowed to spend on behalf of owner through transferFrom. This value changes when approve or transferFrom are called.

Requirements:

  • Contract is initialized.

Constraints:

  • k=10, rows=624

approve #approve

approve(spender: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → Boolean

Sets a value amount of tokens as allowance of spender over the caller’s tokens.

Requirements:

  • Contract is initialized.
  • spender is not the zero address.

Constraints:

  • k=10, rows=452

transferFrom #transferfrom

transferFrom(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → Boolean

Moves value tokens from from to to using the allowance mechanism. value is the deducted from the caller’s allowance.

Transfers to contract addresses are currently disallowed until contract-to-contract interactions are supported in Compact.

This restriction prevents assets from being inadvertently locked in contracts that cannot currently handle token receipt.

Requirements:

  • Contract is initialized.
  • from is not the zero address.
  • from must have a balance of at least value.
  • to is not the zero address.
  • to is not a ContractAddress.
  • The caller has an allowance of ``from’s tokens of at least value`.

Constraints:

  • k=11, rows=1821

_unsafeTransferFrom #_unsafetransferfrom

_unsafeTransferFrom(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → Boolean

Unsafe variant of transferFrom which allows transfers to contract addresses.

Transfers to contract addresses are considered unsafe because contract-to-contract calls are not currently supported.

Tokens sent to a contract address may become irretrievable. Once contract-to-contract calls are supported, this circuit may be deprecated.

Requirements:

  • Contract is initialized.
  • from is not the zero address.
  • from must have a balance of at least value.
  • to is not the zero address.
  • The caller has an allowance of ``from’s tokens of at least value`.

Constraints:

  • k=11, rows=1818

_transfer #_transfer

_transfer(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → []

Moves a value amount of tokens from from to to. This circuit is equivalent to transfer, and can be used to e.g. implement automatic token fees, slashing mechanisms, etc.

Transfers to contract addresses are currently disallowed until contract-to-contract interactions are supported in Compact.

This restriction prevents assets from being inadvertently locked in contracts that cannot currently handle token receipt.

Requirements:

  • Contract is initialized.
  • from is not the zero address.
  • from must have at least a balance of value.
  • to must not be the zero address.
  • to must not be a ContractAddress.

Constraints:

  • k=11, rows=1312

_unsafeUncheckedTransfer #_unsafeuncheckedtransfer

_unsafeUncheckedTransfer(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → []

Unsafe variant of _transfer which allows transfers to contract addresses.

Transfers to contract addresses are considered unsafe because contract-to-contract calls are not currently supported. Tokens sent to a contract address may become irretrievable.

Once contract-to-contract calls are supported, this circuit may be deprecated.

Requirements:

  • Contract is initialized.
  • from is not the zero address.
  • to is not the zero address.

Constraints:

  • k=11, rows=1309

_update #_update

_update(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → []

Transfers a value amount of tokens from from to to, or alternatively mints (or burns) if from (or to) is the zero address.

Requirements:

  • Contract is initialized.

Constraints:

  • k=11, rows=1305

_mint #_mint

_mint(account: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → []

Creates a value amount of tokens and assigns them to account, by transferring it from the zero address. Relies on the update mechanism.

Requirements:

  • Contract is initialized.
  • to is not a ContractAddress.
  • account is not the zero address.

Constraints:

  • k=10, rows=752

_unsafeMint #_unsafemint

_unsafeMint(account: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → []

Unsafe variant of _mint which allows transfers to contract addresses.

Transfers to contract addresses are considered unsafe because contract-to-contract calls are not currently supported.

Tokens sent to a contract address may become irretrievable. Once contract-to-contract calls are supported, this circuit may be deprecated.

Requirements:

  • Contract is initialized.
  • account is not the zero address.

Constraints:

  • k=10, rows=749

_burn #_burn

_burn(account: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → []

Destroys a value amount of tokens from account, lowering the total supply. Relies on the _update mechanism.

Requirements:

  • Contract is initialized.
  • account is not the zero address.
  • account must have at least a balance of value.

Constraints:

  • k=10, rows=773

_approve #_approve

_approve(owner: Either<ZswapCoinPublicKey, ContractAddress>, spender: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → []

Sets value as the allowance of spender over the ``owner’s tokens. This circuit is equivalent to approve`, and can be used to e.g. set automatic allowances for certain subsystems, etc.

Requirements:

  • Contract is initialized.
  • owner is not the zero address.
  • spender is not the zero address.

Constraints:

  • k=10, rows=583

_spendAllowance #_spendallowance

_spendAllowance(owner: Either<ZswapCoinPublicKey, ContractAddress>, spender: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → []

Updates ``owner’s allowance for spenderbased on spentvalue`. Does not update the allowance value in case of infinite allowance.

Requirements:

  • Contract is initialized.
  • spender must have at least an allowance of value from owner.

Constraints:

  • k=10, rows=931