NFTSbt.sol add batchMint method

This commit is contained in:
yuexin 2023-11-03 19:18:09 +08:00
parent b6e6476cab
commit 74c384ab11
3 changed files with 11211 additions and 7992 deletions

5
.gitignore vendored
View File

@ -6,4 +6,7 @@ node_modules
contract_whole
openzeppelin
.key
.addr
.addr
.selfaddr
.selfkey
.env

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,8 @@ contract NFTSbt is AccessControl, ERC721Enumerable {
Counters.Counter private _tokenIdCounter;
uint256 public maxBatchSize = 500;
constructor(
string memory _name,
string memory _symbol,
@ -73,6 +75,28 @@ contract NFTSbt is AccessControl, ERC721Enumerable {
return IMetaData(_metaAddress).getMetaData(address(this), tokenId);
}
function batchMint(
address to,
uint256 count
) external onlyRole(MINTER_ROLE) returns (uint256[] memory) {
require(count > 0, "tokenIds too small");
require(count <= maxBatchSize, "tokenIds too many");
if (supplyLimit > 0) {
require(
(totalSupply() + count) <= supplyLimit,
"Exceed the total supply"
);
}
uint256[] memory tokenIds = new uint256[](count);
for (uint256 i = 0; i < count; i++) {
_tokenIdCounter.increment();
uint256 tokenId = _tokenIdCounter.current();
_safeMint(to, tokenId);
tokenIds[i] = tokenId;
}
return tokenIds;
}
function mint(address to) external onlyRole(MINTER_ROLE) returns (uint256) {
require(to != address(0), "Cannot mint to zero address");
if (supplyLimit > 0) {