0

After deploying token contract on ethereum I am getting 0 decimals being shown on etherscan whilst other explorers displaying correctly.

Image Showing 0 Decimals

I presume because of this Max Total Supply displays as:-

3,200,111,000,000,000,000,000,000,000

When tokens are being sent, it shows the same. However in Metamask, or other explorer shows up as expected.

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";

/**
 * @title MyTestToken
 * @dev A capped ERC20 token contract with preset functionality 0f minter and pauser.
 */
contract MyTestToken is ERC20PresetMinterPauser, ERC20Capped {

    string public constant TOKEN_NAME = "MyTestToken";
    string public constant TOKEN_SYMBOL = "MyTestToken";
    uint256 public constant MAX_SUPPLY = 6300000000;
    uint256 public constant INITIAL_SUPPLY = 2100000000;

    event TokensMinted(address indexed _beneficiary, uint256 _amount, string _context);

    /**
     * @dev Constructor to initialize the token details and mint initial supply.
     * @param _beneficiary The address where initial supply will be minted.
     */

    constructor(address _beneficiary)
        ERC20PresetMinterPauser(TOKEN_NAME, TOKEN_SYMBOL)
        ERC20Capped(MAX_SUPPLY * 1 ether)
    {
        _mint(_beneficiary, INITIAL_SUPPLY *  1 ether);
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override(ERC20, ERC20PresetMinterPauser) {
        super._beforeTokenTransfer(from, to, amount);
    }

    /**
     * @dev Creates amount of new tokens for account.
     *
     * Requirements:
     * - the caller must have the `MINTER_ROLE`.
     *
     * @param _account The address where amount of tokens will be minted.
     * @param _amount The amount of tokens to be minted.
     * @param _purpose The purpose of minting the tokens.
     *
     */

    function mint(address _account, uint256 _amount, string memory _purpose) public {

        super.mint(_account,_amount);

        emit TokensMinted(_account, _amount, _purpose);
    }

    /**
     * @dev Creates amount new tokens for account.
     *
     * See {ERC20-_mint}.
     *
     */
    
    function _mint(
        address account,
        uint256 amount
    ) internal virtual override(ERC20, ERC20Capped) {
        super._mint(account, amount);
    }
}

Can't share token address where this occurred. Will share more information if can replicate. Deploying to testnet and other networks doesn't produce same result.

1 Answer 1

0

Try adding this fn in your code:-

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

and also update the oz libraries with the newer one's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.