Skip to content

Instantly share code, notes, and snippets.

@DonkeVerse
Last active February 22, 2023 07:05
Show Gist options
  • Save DonkeVerse/5219f8250780f9b44b2f0cb4d5f8f17e to your computer and use it in GitHub Desktop.
Save DonkeVerse/5219f8250780f9b44b2f0cb4d5f8f17e to your computer and use it in GitHub Desktop.
pragma solidity 0.8.13;

contract ExampleMint {

    uint256 public constant MAX_SUPPLY = 10000;
    address[MAX_SUPPLY] _owners;
    uint256 public constant PRICE = 0.01 ether;
    uint256 private index = 1;
    
    event TransferSingle(address, address, address, uint256, uint256);

    function mint_efficient_1268F998() external payable {
        require(msg.value == PRICE, "wrong price");
        uint256 _index = index;
        require(_index < MAX_SUPPLY, "supply limit");

        emit TransferSingle(msg.sender, address(0), msg.sender, _index, 1);
        assembly {
            sstore(add(_owners.slot, _index), caller())
        }

        unchecked {
            _index++;
        }
        index = _index;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment