1. NFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/presets/ERC721PresetMinterPauserAutoIdUpgradeable.sol";
contract MyNFT is Initializable, ERC721PresetMinterPauserAutoIdUpgradeable {
function initialize(
string memory name,
string memory symbol,
string memory baseTokenURI
) public virtual override initializer {
__ERC721PresetMinterPauserAutoId_init(name, symbol, baseTokenURI);
}
}
I'm trying to upgrade my nft smartcontract (NFT.sol)
After deploy proxy this contract, I get proxy address and use at another smartcontract to mint NFT like this:
2. Item.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/presets/ERC721PresetMinterPauserAutoIdUpgradeable.sol";
contract Item is
Initializable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
ERC721PresetMinterPauserAutoIdUpgradeable public nft;
function initialize(address _owner, address _nft) public initializer {
__Ownable_init();
transferOwnership(_owner);
nft = ERC721PresetMinterPauserAutoIdUpgradeable(_nft);
}
function mintOneNFT() public nonReentrant {
address buyer = msg.sender;
nft.mint(buyer);
}
}
When i call mintOneNFT:
It has an error like this:
Error: VM Exception while processing transaction: reverted with reason string 'ERC721PresetMinterPauserAutoId: must have minter role to mint'
So, How I grantRole ADMIN and MINTER for MyNFT to mint success?