Set ERC20 decimals to value other than 18

I have created a Standard ERC20 preset with the following code in the Remix IDE

// contracts/ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.2;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.1/contracts/presets/ERC20PresetMinterPauser.sol

I would like to change the Decimals from 18 to lower number

After implementing the contract i was not even able to verify the contract.

I would like to have little help with my first implement of Contracts

1 Like

Hi @Trade_Coin,

Welcome to the community :wave:

To set decimals to a value other than 18, call _setupDecimals in your constructor.

Whilst decimals are for display purposes, I would suggest only changing from the default of 18 when you have a very special reason not to. See: https://docs.openzeppelin.com/contracts/3.x/erc20#a-note-on-decimals

I noticed that you are using OpenZeppelin Contracts 3.0.1. You may want to change this to OpenZeppelin Contracts 3.4 (the latest 3.x version).

Also OpenZeppelin Contracts 4.0 Beta has been released, see announcement: OpenZeppelin Contracts 4.0 Beta


As an aside, see how to Format code in the forum.

1 Like

In Contracts 4.0 Beta, _setupDecimals was removed and the way to use a value other than 18 is now to override the decimals() function.

1 Like

2 posts were split to a new topic: What does it look like to override the decimals function?