What does it look like to override the decimals function?

You're missing the closing brace in the constructor, but it's otherwise ok.

pragma solidity 0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
	constructor () ERC20 ("MyToken", "MTK") {
		_mint(msg.sender, 1000000);
	}

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

18 decimals is the default number of decimals. But you still need to include ... * 10 ** 18 in your mint function call, because numbers of tokens are always expressed in terms of the smallest unit. This means "one token" is actually expressed as 10**18 tokens, or more generally 10**decimals. So in short, the snippet that you shared is correct.

2 Likes