-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Closed
Closed
Copy link
Milestone
Description
🧐 Motivation
ERC1155Supply only counts by token ID. In some cases we may want a general overall count of all tokens that have been minted under the contract. e.g. etherscan and polygonscan tries to call totalSupply() when showing information about an NFT, and shows an error on the page if it failed.
📝 Details
Having only a count for each token ID in ERC1155Supply means to get an overall total count, options are:
- loop through all minted token IDs and call
totalSupply(id) - or not use
ERC1155Supplyand within the ERC1155 contract:
-- use Counters. ButCounterscannot increment by more than 1, which we'd want after a batch mint. Here is an issue about this: Allow Counter increment by more than just 1 #3296
-- or just useuint256instead of bothERC1155SupplyandCounters
I still want to use ERC1155Supply as its purpose is supply tracking. I propose to add overloaded function totalSupply() that returns the overall count.
Some code that could be added are:
uint256 private _totalSupplyAll;
function totalSupply() public view virtual returns (uint256) {
return _totalSupplyAll;
}In _beforeTokenTransfer:
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i];
_totalSupplyAll += amounts[i];
}
}
if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] -= amounts[i];
_totalSupplyAll -= amounts[i];
}
}apecollector
Metadata
Metadata
Assignees
Labels
No labels
