How to fix 5 Common Errors when Creating or Deploying your ERC-20 tokens

Following a simple guide on how to create and launch a cryptocurrency or token, for instance, an ERC-20 token, can sometimes leave you with unresolvable errors. While some errors may completely prevent you from creating a token, like when you get the code wrong or didn’t use the right tool, some errors may reflect on the functionalities or value of the token you created. Fixing a code error requires that you follow the guide carefully, even if you do not have deep knowledge of smart contracts and programming coding languages like solidity. On the other hand, errors that affect the functionalities may imply that you missed some details or steps.


In this article, we will examine 5 common functionality errors that you may experience when or after creating your ERC-20 tokens.

1. Missing decimals () function

Defining decimals () directly affects the value of the token displayed on dapps and wallet; hence, when you forget to implement it, your token will not have any value on exchanges. Usually, the standard decimal for ERC-20 tokens is 18, like Ether $ETH itself. Include this when creating your token by following the example below:


function decimals() public pure override returns (uint8) {
return 18;
}


2. Not Returning a Boolean on transfer() or approve()

For ERC-20 tokens, “transferfrom” and “approve” must return a bool to indicate that a transaction initiated was successful. Omitting this can break compatibility with wallets and dApps. Also, where the status doesn’t return true, other wallets and contracts might think that the transaction initiated failed. For every successful transaction, your token must carry functions that return true to indicate that.


function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;


3. Token created with no minting function

Usually, tokens are created with a certain supply. However, as your project continues to grow, there may be a need to increase the total supply. While a minting function ensures that you can always mint more tokens in the future, it is also vital to keep in mind that there are projects created without such a feature, usually to increase the value of the token over time as the total supply does not increase. However, where you intend to make a token with a minting function, you can add the features with restricted access (onlyOwner or onlyMinter is an example of such restriction).


function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);


4. Deploying on Wrong Blockchain

An ERC-20 token can only be deployed on the Ethereum blockchain or EVM-compatible chains. Deploying the token on a different blockchain leads to severe bottlenecks, such as the token being untradeable on the deployed blockchain due to a lack of compatibility. To fix this, you should:

  • Double-check the hardhat.config.js or truffle-congi.js
  • Use .env files to manage sensitive or environment-specific variables.
  • Confirm instructor arguments before deployment.

5. Failure to include correct token metadata

Every token, whether ERC-20 or BEP-20, has metadata. These are features that determine the token functionalities, compatibility with dapps and wallets, and how it is traded. For instance, a token name and symbol are used to differentiate one token from another; hence, creating a unique token requires that you carefully select a name and symbol that are uncommon.
When creating your token, be sure to pay attention to all the metadata like the ones used below:


constructor() ERC20("TokenName", "TKN") {
_mint(msg.sender, 1_000_000 * 10 ** decimals());
}


Conclusion

Creating a token is not a simple task. Hence, even when pre-written codes make it easy to create a token, paying attention to salient features of the token goes a long way in determining how a token is identified and traded in the marketplace. This is where the developer must take caution to ensure that tokens are carefully created with the necessary features. However, errors must be swiftly attended to when they are detected.

See our previous article on:

How to create ERC-20 token

How to crowdsale your token