Skip to content

Instantly share code, notes, and snippets.

Last active May 1, 2021
What would you like to do?
Storage optimizations

In the contract we are storing the following variables:

    mapping(uint256 => address) private idToCreator;
    mapping(uint256 => address) internal idToOwner;
    mapping(uint256 => uint256) public idToCreatorNft;
    mapping(uint256 => uint256) public creatorNftMints;
    mapping(uint256 => address) internal idToApproval;
    mapping(address => mapping(address => bool)) internal ownerToOperators;
    mapping(address => uint256[]) internal ownerToIds;
    mapping(uint256 => uint256) internal idToOwnerIndex;

Most of these variables could be store using a struct instead of multiple mappings. Using stuct over mapping offers better storage optimizations. Here you have more information:

Also, creatorNftMints is only used in mintWithAlphaOrBeta. In this method, we validate that is only minted or not. For this purpose, we could use mapping(uint256 => bool) instead mapping(uint256 => uint256).

function mintWithAlphaOrBeta(uint256 _createVia)
        returns (uint256)
            creatorNftMints[_createVia] == 0,
            "Already minted with this alpha/beta"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment