I'm trying to specify the amount of decimals of a token using OpenZeppelin. This will cause a compilation error:

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {

   constructor() ERC20("my token", "a")  {
       // _mint(..... )
     _setupDecimals(4); //  – undefined identifier


What's the matter?

1 Answer 1


_setupDecimals is not a function of the normal OpenZepplin ERC20 contract.

To change the decimals you can override the decimals function and return another value.

Edit: This is also mentioned in the constructor documentation of the ERC20 contract:

The default value of {decimals} is 18. To select a different value for {decimals} you should overload it.

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.