ERC20 (Advanced)

Advanced features of the ERC20 token

The ERC20 token is designed to handle a fairly wide array of use cases and programming maneuvers. If you havenโ€™t read about those, then click below first, as the following information moves forward from the basic context and information presented in that article.

pageERC20 (Ethereum)

The ERC20 standard has recently been enhanced for greater functionality by Flexsmart hub, contracts and extensions. These improvements are robust, performant, secure and battle-tested. Our resources are upgraded periodically, so it is important to watch the change logs related to any code you access from our repository.

The core set of contracts we offer are unopinionated, meaning a developer can expose their functions any way they prefer. Some of the โ€œpresetโ€ contracts use opinionated patterns in order to provide ready-to-use functionality that doesn't require advanced programming expertise to deploy.

Following is a breakdown of our new augmentations to the ERC20 token standard:

1.Access Control (Roles)

This is a contract module that allows for the implementation of role-based access control mechanisms. Such roles can be granted and revoked dynamically, and an admin role is designated for that purpose. An external interface is also available, as well as an extension that allows for the enumeration of members so that they can be individually identified and counted.

2.Ownable

This contract module offers a simple mechanism that allows for a single owner role and a single account. It has basic functionality related to those needs and is mostly used for testing.

3.UUPSUpgradeable

This mechanism is designed for UPS proxies based on the universal upgradeable proxy standard provided by Ethereum in their ERC1967 specification. Proxy contracts allow developers to change code that is installed on the blockchain--after it has already been committed! This important innovation sidesteps one of the most serious drawbacks to chain-implemented programming; once a block has been mined, any code within it is thereafter normally immutable, and cannot be fixed or upgraded as is readily done with centralized server code stores. Note that if your contract is going to be deployed with upgradeability you will need to use the upgradeable variant of Flexsmart contracts. In that scenario, constructors are replaced by initializer functions and state variables are declared in initializer functions.

4.Transparent UpgradeableProxy

This contract implements a proxy using the transparent proxy pattern. This scheme protects the proxy implementation from changes attempted through the admin account, which can be used to compromise the contract.

5.Mint

This function allows for the creation of new tokens and assigns them to a designated account.

6.Burn

This function destroys a designated quantity of tokens from an account, which reduces the total supply of tokens. The ERCBurnable extension also allows token holders to destroy tokens in a way that can be evaluated off-chain using event analysis.

7.TotalSupply

This function returns the total quantity of tokens that are in circulation as of that moment.

8.Pausable

This extension allows developers to pause the minting, burning and transfer of tokens. This can be useful when actions like token trades need to be executed in a specific order during an evaluation period (typically scheduled at the end). It also provides a way to stop all token transfers in an emergency scenario.

9.Votes

One of the crucial developments of the Ethereum platform is the implementation of a voting mechanism that allows token holders to cast their opinion on an issue that requires a community verdict. This arises constantly as the Ethereum organization is steered and improved according to the democratic consensus of its participants. This extension keeps a history of each accountโ€™s vote power, which is not by default scaled by token balance.

10.Permit

This extension allows changes to an accountโ€™s allowance to be made without requiring a transaction--and therefore a supply of Ether to pay for the gas required. Approvals are made using signatures instead. The spirit behind this extension is to keep the Ethereum network functional for parties that do not actually own the native coin. Note that this is a draft proposal as of 12/2021.

11.FlashMint

This is a new implementation of the ERC3156 flash loans extension. It adds the flashloan method, which provides support for flash loans at the token level. There is no fee by default, but this can be overridden. The receiver is required to implement the IERC3156 flash borrower interface.

12.Snapshot

Many functions and extensions of the ERC20 token standard are devised to thwart attacks like โ€œdouble spendingโ€ or reduce gas fees associated with a transaction. This extension does both. When a snapshot is created account balances and total supply are recorded for later access. Information that is identical from one snapshot to the next is stored as a single entry and does not incur new gas fees.

13.SupplyTracking

This extension keeps track of the total supply of tokens.

Additional Notes

FlexSmart contracts use a stable application programming interface, which means that contracts written using our libraries wonโ€™t break older code. This is only true for minor version upgrades however. The contracts we provide should always be used โ€œas-isโ€ by importing them. They are designed so that only the functions you actually use are deployed, which avoids the high gas fees that could be incurred by indiscriminately copying and pasting code into your projects.

Tip: Not sure where to start? Use our FlexSmart platform to generate your own ERC20 token!

Last updated