Skip to main content

ERC20Minimal

Git Source

Authors: Axicon Labs Limited, Modified from Solmate (https://github.com/transmissions11/solmate/blob/v7/src/tokens/ERC20.sol)

The metadata must be set in the inheriting contract.

Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.

State Variables

totalSupply

The total supply of tokens.

This cannot exceed the max uint256 value.

uint256 public totalSupply;

balanceOf

Token balances for each user

mapping(address account => uint256 balance) public balanceOf;

allowance

Stored allowances for each user.

Indexed by owner, then by spender.

mapping(address owner => mapping(address spender => uint256 allowance)) public allowance;

Functions

approve

Approves a user to spend tokens on the caller's behalf.

function approve(address spender, uint256 amount) public returns (bool);

Parameters

NameTypeDescription
spenderaddressThe user to approve
amountuint256The amount of tokens to approve

Returns

NameTypeDescription
<none>boolWhether the approval succeeded

transfer

Transfers tokens from the caller to another user.

function transfer(address to, uint256 amount) public virtual returns (bool);

Parameters

NameTypeDescription
toaddressThe user to transfer tokens to
amountuint256The amount of tokens to transfer

Returns

NameTypeDescription
<none>boolWhether the transfer succeeded

transferFrom

Transfers tokens from one user to another.

Supports token approvals.

function transferFrom(address from, address to, uint256 amount) public virtual returns (bool);

Parameters

NameTypeDescription
fromaddressThe user to transfer tokens from
toaddressThe user to transfer tokens to
amountuint256The amount of tokens to transfer

Returns

NameTypeDescription
<none>boolWhether the transfer succeeded

_transferFrom

Internal utility to transfer tokens from one user to another.

function _transferFrom(address from, address to, uint256 amount) internal;

Parameters

NameTypeDescription
fromaddressThe user to transfer tokens from
toaddressThe user to transfer tokens to
amountuint256The amount of tokens to transfer

_mint

Internal utility to mint tokens to a user's account.

function _mint(address to, uint256 amount) internal;

Parameters

NameTypeDescription
toaddressThe user to mint tokens to
amountuint256The amount of tokens to mint

_burn

Internal utility to burn tokens from a user's account.

function _burn(address from, uint256 amount) internal;

Parameters

NameTypeDescription
fromaddressThe user to burn tokens from
amountuint256The amount of tokens to burn

Events

Transfer

Emitted when tokens are transferred

event Transfer(address indexed from, address indexed to, uint256 amount);

Parameters

NameTypeDescription
fromaddressThe sender of the tokens
toaddressThe recipient of the tokens
amountuint256The amount of tokens transferred

Approval

Emitted when a user approves another user to spend tokens on their behalf

event Approval(address indexed owner, address indexed spender, uint256 amount);

Parameters

NameTypeDescription
owneraddressThe user who approved the spender
spenderaddressThe user who was approved to spend tokens
amountuint256The amount of tokens approved to spend