Skip to content

Commit

Permalink
bulk mint and updateURI added
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit-bitpack committed Feb 27, 2024
1 parent 867d1b4 commit 0cccc7b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
12 changes: 6 additions & 6 deletions contracts/AppNFTUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,15 @@ contract AppNFTUpgradeable is Initializable, ERC721Upgradeable, ERC721Enumerable
/**
* @dev Mint multiple NFTs and assign them to a specified address.
* @param to The address to assign the minted NFTs to.
* @param appNames An array of app names to use for the NFTs.
* @param names An array of names to use for the NFTs.
* @param uris An array of URIs to use for the NFTs.
*/
function bulkMintAndURIupdate(address[] calldata to, uint256[] calldata tokenIds, string[] calldata appNames, string[] calldata uris) external onlyOwner {
uint256 quantity = appNames.length;
require(quantity == uris.length, "appNames and uris length mismatch");
for (uint256 i = 0; i < appNames.length; i++) {
function bulkMintAndURIupdate(address[] calldata to, uint256[] calldata tokenIds, string[] calldata names, string[] calldata uris) external onlyOwner {
uint256 quantity = tokenIds.length;
require(quantity == uris.length, "tokenIds and uris length mismatch");
for (uint256 i = 0; i < tokenIds.length; i++) {
if(tokenIds[i] == 0){
mint(to[i], uris[i], appNames[i]);
mint(to[i], uris[i], names[i]);
} else {
_setTokenURI(tokenIds[i], uris[i]);
}
Expand Down
31 changes: 31 additions & 0 deletions contracts/AppStoreNFTUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,37 @@ contract AppStoreNFTUpgradeable is Initializable, ERC721Upgradeable, ERC721Enume
require(_to.send(amount), 'Fee Transfer to Owner failed.');
}

/**
* @dev Mint multiple NFTs and assign them to a specified address.
* @param to The address to assign the minted NFTs to.
* @param names An array of names to use for the NFTs.
* @param uris An array of URIs to use for the NFTs.
*/
function bulkMintAndURIupdate(address[] calldata to, uint256[] calldata tokenIds, string[] calldata names, string[] calldata uris) external onlyOwner {
uint256 quantity = tokenIds.length;
require(quantity == uris.length, "tokenIds and uris length mismatch");
for (uint256 i = 0; i < tokenIds.length; i++) {
if(tokenIds[i] == 0){
mint(to[i], uris[i], names[i]);
} else {
_setTokenURI(tokenIds[i], uris[i]);
}
}
}

/**
* @dev Transfer multiple NFTs from one address to another.
* @param to The address to transfer the NFTs to.
* @param tokenIds An array of token IDs to transfer.
*/
function bulkTransfer(address to, uint256[] calldata tokenIds) external {
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
require(_isApprovedOrOwner(_msgSender(), tokenId), "Caller is not owner nor approved");
_transfer(_msgSender(), to, tokenId);
}
}

/**
* @notice function to set trusted forwarder
* @dev only owner can call this function
Expand Down
31 changes: 31 additions & 0 deletions contracts/DevNFTUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,37 @@ contract DevNFTUpgradeable is Initializable, ERC721Upgradeable, ERC721Enumerable
require(_to.send(amount), 'Fee Transfer to Owner failed.');
}

/**
* @dev Mint multiple NFTs and assign them to a specified address.
* @param to The address to assign the minted NFTs to.
* @param names An array of names to use for the NFTs.
* @param uris An array of URIs to use for the NFTs.
*/
function bulkMintAndURIupdate(address[] calldata to, uint256[] calldata tokenIds, string[] calldata names, string[] calldata uris) external onlyOwner {
uint256 quantity = tokenIds.length;
require(quantity == uris.length, "tokenIds and uris length mismatch");
for (uint256 i = 0; i < tokenIds.length; i++) {
if(tokenIds[i] == 0){
mint(to[i], uris[i], names[i]);
} else {
_setTokenURI(tokenIds[i], uris[i]);
}
}
}

/**
* @dev Transfer multiple NFTs from one address to another.
* @param to The address to transfer the NFTs to.
* @param tokenIds An array of token IDs to transfer.
*/
function bulkTransfer(address to, uint256[] calldata tokenIds) external {
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
require(_isApprovedOrOwner(_msgSender(), tokenId), "Caller is not owner nor approved");
_transfer(_msgSender(), to, tokenId);
}
}

/**
* @notice function to set trusted forwarder
* @dev only owner can call this function
Expand Down
1 change: 1 addition & 0 deletions scripts/upgradeDevProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var file = require("./config.json");
async function main() {
const DevNFT = await ethers.getContractFactory("DevNFTUpgradeable");
const devNFT = await upgrades.upgradeProxy(file.DevNFTUpgradeable, DevNFT, [
file.DappNameList,
process.env.TRUSTED_FORWARDER_ADDRESS,
]);
console.log("DevNFT upgraded", devNFT);
Expand Down

0 comments on commit 0cccc7b

Please sign in to comment.