API Reference

FungibleToken API

This module provides the full FungibleToken module API.

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

import "./node_modules/@openzeppelin/compact-contracts/token/FungibleToken";

Ledger

_isInitialized: Boolean

ledger

#

Initialization flag, tracked per-module to avoid the compiler's shared transitive-dependency state bug (LFDT-Minokawa/compact#270). See the Initializable module for rationale.

_balances: Map<Either<Bytes<32>, ContractAddress>, Uint<128>>

ledger

#

Mapping from account addresses to their token balances.

_allowances: Map<Either<Bytes<32>, ContractAddress>, Map<Either<Bytes<32>, ContractAddress>, Uint<128>>>

ledger

#

Mapping from owner accounts to spender accounts and their allowances.

_totalSupply: Uint<128>

ledger

#

Total tokens in circulation. _update raises it on a mint and lowers it on a burn, rejecting an increase that would overflow Uint<128>.

_name: Opaque<"string">

sealed ledger

#

The token's human-readable name, set once at construction.

_symbol: Opaque<"string">

sealed ledger

#

The token's ticker symbol, set once at construction.

_decimals: Uint<8>

sealed ledger

#

The number of decimals used to display balances, set once at construction. Purely presentational; no circuit scales by it.

Witnesses

wit_FungibleTokenSK() → Bytes<32>

witness

#

Returns the caller's secret key used in deriving the account identifier.

The same key produces the same account identifier across all contracts. Users who desire cross-contract unlinkability should use different keys per contract.

Circuits

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

circuit

#

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.

name() → Opaque<"string">

circuit

#

Returns the token name.

Requirements:

  • Contract is initialized.
k=6, rows=26

symbol() → Opaque<"string">

circuit

#

Returns the symbol of the token.

Requirements:

  • Contract is initialized.
k=6, rows=26

decimals() → Uint<8>

circuit

#

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

Requirements:

  • Contract is initialized.
k=6, rows=26

totalSupply() → Uint<128>

circuit

#

Returns the value of tokens in existence.

Requirements:

  • Contract is initialized.
k=6, rows=26

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

circuit

#

Returns the value of tokens owned by account.

Manually checks if account is a key in the map and returns 0 if it is not.

Requirements:

  • Contract is initialized.
k=10, rows=668

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

circuit

#

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.
k=13, rows=3743

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

circuit

#

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.
k=13, rows=3740

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

circuit

#

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.

Manually checks if owner and spender are keys in the map and returns 0 if they are not.

Requirements:

  • Contract is initialized.
k=11, rows=1350

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

circuit

#

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.
k=13, rows=3066

transferFrom(
  fromAddress: Either<Bytes<32>, ContractAddress>,
  to: Either<Bytes<32>, ContractAddress>,
  value: Uint<128>
) → Boolean

circuit

#

Moves value tokens from fromAddress 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.
  • fromAddress is not the zero address.
  • fromAddress 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 fromAddress's tokens of at least value.
k=13, rows=4906

_unsafeTransferFrom(
  fromAddress: Either<Bytes<32>, ContractAddress>,
  to: Either<Bytes<32>, ContractAddress>,
  value: Uint<128>
) → Boolean

circuit

#

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.
  • fromAddress is not the zero address.
  • fromAddress must have a balance of at least value.
  • to is not the zero address.
  • The caller has an allowance of fromAddress's tokens of at least value.
k=13, rows=4903

_transfer(
  fromAddress: Either<Bytes<32>, ContractAddress>,
  to: Either<Bytes<32>, ContractAddress>,
  value: Uint<128>
) → []

circuit

#

Moves a value amount of tokens from fromAddress 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.
  • fromAddress is not the zero address.
  • fromAddress must have at least a balance of value.
  • to must not be the zero address.
  • to must not be a ContractAddress.
k=12, rows=2125

_unsafeUncheckedTransfer(
  fromAddress: Either<Bytes<32>, ContractAddress>,
  to: Either<Bytes<32>, ContractAddress>,
  value: Uint<128>
) → []

circuit

#

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.
  • fromAddress is not the zero address.
  • to is not the zero address.
k=12, rows=2122

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

circuit

#

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

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.
  • account is not a ContractAddress.
  • account is not the zero address.
k=11, rows=1328

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

circuit

#

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.
k=11, rows=1325

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

circuit

#

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.
k=11, rows=1268

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

circuit

#

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.
k=11, rows=1407

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

circuit

#

Updates owner's allowance for spender based on spent value. 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.
k=11, rows=1935