ERC20Minimal
Title: Minimal efficient ERC20 implementation without metadata
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 _internalSupply, as the sum of all user balances must not exceed it.
State Variablesβ
_internalSupplyβ
The internal supply of tokens.
This cannot exceed the max uint256 value.
uint256 internal _internalSupply
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
| Name | Type | Description |
|---|---|---|
spender | address | The user to approve |
amount | uint256 | The amount of tokens to approve |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether the approval succeeded |
transferβ
Transfers tokens from the caller to another user.
function transfer(address to, uint256 amount) public virtual returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
to | address | The user to transfer tokens to |
amount | uint256 | The amount of tokens to transfer |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether 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
| Name | Type | Description |
|---|---|---|
from | address | The user to transfer tokens from |
to | address | The user to transfer tokens to |
amount | uint256 | The amount of tokens to transfer |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether the transfer succeeded |
_transferFromβ
Internal utility to transfer tokens from one user to another.
function _transferFrom(address from, address to, uint256 amount) internal;
Parameters
| Name | Type | Description |
|---|---|---|
from | address | The user to transfer tokens from |
to | address | The user to transfer tokens to |
amount | uint256 | The amount of tokens to transfer |
_mintβ
Internal utility to mint tokens to a user's account.
function _mint(address to, uint256 amount) internal;
Parameters
| Name | Type | Description |
|---|---|---|
to | address | The user to mint tokens to |
amount | uint256 | The amount of tokens to mint |
_burnβ
Internal utility to burn tokens from a user's account.
function _burn(address from, uint256 amount) internal;
Parameters
| Name | Type | Description |
|---|---|---|
from | address | The user to burn tokens from |
amount | uint256 | The amount of tokens to burn |
Eventsβ
Transferβ
Emitted when tokens are transferred.
event Transfer(address indexed from, address indexed to, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
from | address | The sender of the tokens |
to | address | The recipient of the tokens |
amount | uint256 | The 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
| Name | Type | Description |
|---|---|---|
owner | address | The user who approved the spender |
spender | address | The user who was approved to spend tokens |
amount | uint256 | The amount of tokens approved to spend |