When I create a token, how do I specify how much of it I want to hold for myself and not offer for sale? I have seen the mint and burn functions and those would be ideal to implement as well. I don't really want to do a crowdsale just a simple token that can be bought/sold on an exchange.

1 Answer 1


There are several ways to achieve what you want, but before giving my answer, I recommend you acquaint yourself with the ERC-20 specification.

First things first, you need a token implementation. I suggest you use OpenZeppelin's ERC20.sol (it's known to be safe, battle-tested in many many projects).

Then, you basically inherit from the ERC20 contract and augment the functionality as you wish. Here's one way to allocate a specific amount of tokens to yourself:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract MyERC20 is ERC20 {
    constructor(string memory name_, string memory symbol_) ERc20(name_, symbol_, 18) {
        // Mint 1 billion tokens to the contract creator.
        _mint(msg.sender, 1000000000000000000000000000);

The code above will allocate 1 billion tokens (recall that the token has 18 decimals by default, so 1 billion is represented as 1e27) to msg.sender. You could alternatively pass a third argument to the constructor and mint the tokens to that account instead.

I recommend using this technique because it's the most transparent way of distributing the initial token balances. Contract readers will see that there is no risk of inflating the token supply, ever.

However, if you want to keep the possibility of inflation, you should inherit from Ownable and implement a custom mint method that is protected by the onlyOwner modifier.

  • Thanks, I like your thinking. I like the idea of it being inflation-proof, but would I still be able to add burning down the line? Or would I have to use onlyOwner for that? Also, what do you think is a good total initial supply of tokens?
    – loginus
    May 18, 2021 at 18:04
  • For burning, you will have to write another function called burn, and yes inherit from Ownable unless you want everyone to be able to burn your tokens. May 18, 2021 at 19:16
  • Regarding token supplies, I can't give any advice on that. It's a completely subjective matter. May 18, 2021 at 19:16
  • Is the initial minting of coins to the owner then subtracted from the total supply? Minting is new coins so it would be additional, correct? So max supply would increase?
    – loginus
    Jun 18, 2021 at 5:11
  • Yes, to both questions. Read the EIP-20 standard. Jun 18, 2021 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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