Skip to main content

ERC20

This abstract contract is a gas-efficient ERC20 and EIP-2612 implementation. It is a modified version of Solmate ERC20 implementing the basic IERC20.

The contract is ERC20 compliant and inherits the standard IERC20 interface.

This page is split up differently (than other contract pages) showing the public metadata, ERC20 and EIP-2612 storage variables, and the ERC20 and EIP-2612 logic within the ERC20 contract. The source code is available on GitHub.

Metadata Storage

name

string public name

The name of the token.

symbol

string public symbol

The symbol of the token.

decimals

uint8 public immutable decimals

The number of decimals the token uses.

ERC20 Storage

totalSupply

uint256 public totalSupply

The total supply of tokens.

EIP-2612 Storage

bytes32 public constant PERMIT_TYPEHASH = keccak256(Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline))

ERC20 Logic

approve

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

Allows the spender to withdraw from the account up to the amount.

Input Parameters:

NameTypeDescription
spenderaddressThe address of the user to approve to withdraw tokens
amountuint256The amount of tokens the spender can withdraw

Return Values:

TypeDescription
boolReturns true if the operation was successful, reverts otherwise

transfer

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

Transfers the amount of tokens to the to address.

Input Parameters:

NameTypeDescription
toaddressThe address to send the tokens to
amountunit256The amount of tokens to transfer

Return Values:

TypeDescription
boolReturns true if the operation was successful, reverts otherwise

transferFrom

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

Transfers the amount of tokens from the from address to the to address.

Input Parameters:

NameTypeDescription
fromaddressThe address to transfer the tokens from
totoThe address to transfer the tokens to
amountuint256The amount of tokens to transfer

Return Values:

TypeDescription
boolReturns true if the operation was successful, reverts otherwise

EIP-2612 Logic

permit

function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual

Allows a user to permit another account (or contract) to use their funds using a signed message. This enables gas-less transactions and single approval/transfer transactions. Allow passing a signed message to approve spending.

Input Parameters:

NameTypeDescription
owneraddressThe owner of the funds
spenderaddressThe spender of the funds
valueuint256The amount the spender is permitted to spend
deadlineuint256The deadline timestamp, use type(uint256).max for max/no deadline
vuint8The V signature parameter
rbytes32The R signature parameter
sbytes32The S signature parameter

DOMAIN_SEPARATOR

function DOMAIN_SEPARATOR() public view virtual returns (bytes32)

Gets the domain separator for the token. Returns the cached value if the chainId matches cache, otherwise recomputes separator.

Return Values:

TypeDescription
bytes32The domain separator of the token at current chain