The Capsule NFT Contract

The Capsule NFT contract ("Capsule contract") is the base ERC-721 NFT utilized by the Capsule Protocol. The other contracts (CapsuleFactory.sol and CapsuleMinter.sol) mint, burn, and interact with this contract. Any NFT generated from the Capsule Protocol is of this type.

A new instance of this contract is deployed each time a Capsule Collection is created.

View an example of Capsule.sol verified contract code on Etherscan

User Interactable Methods


function lockCollectionCount(uint256 _nftCount) external virtual

Usage: Lock the collection at a provided NFT count (the collection total Capsule NFT count), preventing any further minting past the given number. The set maxId of this collection will be the provided NFT count minus one, for clarity (without subtracting 1, a lock count of 15 would provide for 16 NFTs, as it includes the 0 count).


  • _name: (uint256) - the count at which to lock the Capsule Collection from further minting


function isCollectionLocked() public view returns (bool)

Usage: Check if the Capsule Collection is locked. This is checked by ensuring the maxId is less than the counter.

Parameters: (none)


function transferOwnership(address _newOwner) public virtual

Usage: Transfer ownership of the Capsule to _newOwner. The new owner of the Capsule NFT will be able to call any owner-only methods from the contract.


  • _account: (address) - The address (account) to pass ownership onto. This can also be the zero address.


function tokenURI(uint256 tokenId) public view returns (string)

Usage: Check the tokenURI of a Capsule at id tokenId. The tokenURI will map to the NFT metadata.


  • _tokenId: (uint256) - the id of the NFT


function setTokenURI(uint256 _tokenId, string _newTokenURI) external

Usage: Set new token URI for a given tokenId. Only the tokenURI owner, also known as the Metamaster, can set a new URI.


  • _tokenId: (uint256) - the id of the NFT to burn

  • _newTokenURI: (string) - the new NFT at _tokenId's tokenURI


function updateTokenURIOwner(address _newTokenURIOwner) external

Usage: Update the tokenURIowner. Only the tokenURIOwner, also known as the Metamaster, can call this function.


  • _account: (address) - The new address to become the tokenURIOwner (Metamaster)


function isCollectionMinter(address _account) external view returns (bool)

Usage: Check if the passed in address of _account is allowed to mint from the collection.


  • _account: (address) - The address (account) to check


function exists(uint256 tokenId) external view returns (bool)

Usage: Check if a Capsule (at id tokenId) of the current collection exists.


  • _tokenId: (uint256) - the id of the NFT

User Non-Interactable Methods


constructor(string _name, string _symbol, address _tokenURIOwner, bool _isCollectionPrivate) public

Usage: Called upon creation of Capsule. The CapsuleFactory calls the constructor upon creation of a Capsule Collection.


  • _name: (string) - the name of the Capsule Collection

  • _symbol: (string) - the symbol of the Capsule Collection

  • _tokenURIOwner: (address) - the address of the Capsule Collection tokenURIOwner (also known as the Metamaster)

  • _isCollectionPrivate: (boolean) - whether the Capsule Collection is designated as private


function mint(address _account, string _uri) external

Usage: Create an NFT from this collection. This method is uneditable by users, as only the CapsuleMinter may mint NFTs from this collection. Users interact with this mint through the CapsuleMinter's mintCapsule methods.


  • _account: (address) - the account to receive the NFT

  • _uri: (string) - the set NFT tokenURI


function burn(address _account, uint256 _tokenId) external

Usage: Burn an NFT from this collection. This method is uneditable by users, as only the CapsuleMinter may burn NFTs from this collection. Users interact with this burn through the CapsuleMinter's burnCapsule methods.


  • _account: (address) - the account that is burning the NFT

  • _tokenId: (uint256) - the id of the NFT to burn

Key Constants


string VERSION

Usage: The current version.


uint256 counter

Usage: The current Capsule Collection counter (used as an id).


uint256 maxId

Usage: The maximum id the collection is allowed to mint up to (this may also be set to the MaxUInt256 to signify no maximum). The maxId may be set to a number lower than the current counter or id, in which case no further Capsules may be minted from this collection.


contract ICapsuleFactory factory

Usage: The address of the CapsuleFactory this Capsule is attached to.


address tokenURIOwner

Usage: The current tokenURIOwner of the collection - this parameter may also be known as the 'Metamaster'.


bool isCollectionPrivate

Usage: A boolean which designates whether the collection is private (true) or public (false).

Lesser Interesting Functions


function supportsInterface(bytes4 interfaceId) public view returns (bool)


function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal


function _burn(uint256 tokenId) internal



modifier onlyMinter()

Key Events


event TokenURIOwnerUpdated(address oldOwner, address newOwner)


event TokenURIUpdated(uint256 tokenId, string oldTokenURI, string newTokenURI)

Last updated