Skip to main content

ERC-20 Mint Module

Internal functions for minting ERC-20 tokens

Key Features
  • Provides internal functions for facet composition.
  • Utilizes the diamond storage pattern (EIP-8042) for shared state.
  • No external dependencies or using directives.
  • Minimal gas overhead due to direct storage manipulation.
Module Usage

This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.

Overview

This module provides internal functions for minting ERC-20 tokens. Facets can import this module to manage token creation using shared diamond storage. Changes to total supply and recipient balances are immediately reflected across all facets accessing the same storage.

Storage

ERC20Storage

Definition
struct ERC20Storage {
mapping(address owner => uint256 balance) balanceOf;
uint256 totalSupply;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc20"))

Functions

getStorage

Returns a pointer to the ERC-20 storage struct. Uses inline assembly to bind the storage struct to the fixed storage position.

function getStorage() pure returns (ERC20Storage storage s);

Returns:

PropertyTypeDescription
sERC20StorageThe ERC-20 storage struct.

mint

Mints new tokens to a specified address. Increases both total supply and the recipient's balance.

function mint(address _account, uint256 _value) ;

Parameters:

PropertyTypeDescription
_accountaddressThe address receiving the newly minted tokens.
_valueuint256The number of tokens to mint.

Events

Errors

Best Practices

Best Practice
  • Ensure that access control for minting is enforced by the calling facet.
  • Verify storage layout compatibility when upgrading or adding facets to avoid storage collisions.
  • Handle the ERC20InvalidReceiver error if the minting logic were to incorporate checks for valid recipients.

Integration Notes

Shared Storage

This module interacts with diamond storage at a fixed position identified by keccak256(\"erc20\"). It reads and writes to the ERC20Storage struct, specifically modifying totalSupply. All state changes made by mint are immediately visible to any other facet that reads from the same storage position within the diamond.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.