ERC1155Supply
ERC1155Supply
Inherits: ERC1155
Extension of ERC1155 that adds tracking of total supply per id. Useful for scenarios where Fungible and Non-fungible tokens have to be clearly identified. Note: While a totalSupply of 1 might mean the corresponding is an NFT, there is no guarantees that no other token with the same id are not going to be minted.
State Variables
_totalSupply
keeps track of per-token id's total supply, as well as overall supply. also used as a counter when minting, by reading the .length property of the array.
uint256[] internal _totalSupply;Functions
totalSupply
Returns the total supply of a specific token ID.
The total value transferred from address 0x0 minus the total value transferred to 0x0 observed via the TransferSingle and TransferBatch events MAY be used by clients and exchanges to determine the βcirculating supplyβ for a given token ID.
function totalSupply(uint256 _id) public view returns (uint256);Parameters
_id
uint256
The token ID to query.
Returns
<none>
uint256
The total supply of the token.
totalSupply
Returns the total number of unique token IDs in this collection.
Required in order to enumerate _totalSupply (or _tokenURIs, see ERC1155Metadata_URI-uri) from a client.
Returns
<none>
uint256
The total number of unique token IDs.
exists
Checks if a token exists with a given ID.
Note that for implementations such as open editions, token IDs with a supply of 0 may exist, i.e. minting with 0 supply may be intentional. Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. Tokens start existing when they are minted (_mint), and stop existing when they are burned (_burn).
Parameters
_id
uint256
The token ID to check.
Returns
<none>
bool
True if the token exists, false otherwise.
_mint
Mints a new token.
Because _mint is never (and MUST not be) invoked in order to mint additional supply for an existing tokenId, it is more efficient to push a new element into the array rather than writing to an arbitrary index such as _totalSupply[_id] += _totalSupply. For this reason it was named more aptly _totalSupply, rather than _value.
Parameters
_to
address
The address to mint the token to.
_id
uint256
The token ID; the child/derived contract is responsible for calculating it.
totalSupply_
uint256
The total supply for the new token.
_data
bytes
The data to associate with the token.
_burn
Burns a specific token.
totalSupply MUST be incremented before transfering the control flow to _mint, which could include external calls, which could result in reentrancy. E.g. https://medium.com/chainsecurity/totalsupply-inconsistency-in-erc1155-nft-tokens-8f8e3b29f5aa
Since _balanceOf has been decremented by the base contract _burn function by calling super._burn first, and since the sum of balances can never exceed totalSupply, we can safely decrement totalSupply without requiring to check for underflow. Since there are no external calls being made in _burn, there is no risk of reentrancy that could exploit _totalSupply.
Parameters
_from
address
The owner of the token.
_id
uint256
The token ID to burn.
_value
uint256
The amount of tokens to burn.
Last updated