Specify max supply ERC20

erc-20remixsolidityweb3js

im creating an ERC20 token and i want to specify a maximium supply for my token?

I want to mint 2000 tokens.

1000 of that tokens to my wallet, and leave in the contract the other 1000 tokens.

Is that possibly?

Best Answer

You can achieve this with OpenZeppelin using the following code:

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

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

contract ERC20FixedSupply is ERC20 {
    constructor() ERC20("Fixed", "FIX") {
        _mint(msg.sender, 1000); // Mints 1000 tokens to your wallet
        _mint(address(this), 1000); // Mints 1000 tokens to the contract
    }
}

There's some more info in the docs here!

Related Topic