Flash-Git asked on GitHub (https://github.com/OpenZeppelin/openzeppelin-contracts/issues/2142):
ERC721Mintable
is missing from /ERC721/ despite being in the README alongside ERC721Burnable
and ERC721Pausable
.
I checked a few open issues and I can't find any direct reference to this.
The master
branch of the repo currently contains the work for the upcoming OpenZeppelin Contracts 3.0 (currently a release candidate).
Access control has been redesigned and the current role contracts have been removed, including MinterRole
. Since this role has been removed, ERC721Mintable
which uses MinterRole
has also been removed.
Okay, after looking through the new access control design, I can definitely see the appeal!
Although I couldn’t find anything on the master branch that lets me allow minting after deployment (or any other roles/access functionality) without completely writing my own extension. The access folder on master doesn’t contain very much. I would expect to see something more akin to this and then see an example implementation [like this] => branch v2.4.0 - token/ERC721/ERC721Mintable.sol. (new user restriction)
Where am I supposed to be looking if I want to add 0.6.x minting functionality? I’m still confused.
1 Like
Hi @FlashyQpt,
OpenZeppelin Contracts 3.0 is currently a release candidate.
I have created an example mintable ERC721 token
The following smart contract hasn’t been tested or audited
Token.sol
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/token/ERC721/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721Metadata.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract Token is ERC721Enumerable, ERC721Metadata, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() public ERC721Metadata("Token", "TKN") {
_grantRole(MINTER_ROLE, msg.sender);
_setBaseURI("https://example.com/tokens/");
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
virtual
override(ERC721Enumerable, ERC721Metadata)
{
super._beforeTokenTransfer(from, to, tokenId);
}
function mint(address to) public {
require(
hasRole(MINTER_ROLE, msg.sender),
"Token: account does not have minter role"
);
_tokenIds.increment();
uint256 newTokenId = _tokenIds.current();
_mint(to, newTokenId);
_setTokenURI(newTokenId, Strings.fromUint256(newTokenId));
}
}
Deploy
Using OpenZeppelin CLI 2.8 (currently release candidate)
$ npx oz deploy
✓ Compiled contracts with solc 0.6.4 (commit.1dca32f3)
Compilation warnings:
@openzeppelin/contracts/utils/Address.sol:55:28: Warning: Using ".value(...)" is deprecated. Use "{value: ...}" instead.
(bool success, ) = recipient.call.value(amount)("");
^------------------^
? Choose the kind of deployment regular
? Pick a network development
? Pick a contract to deploy Token
✓ Deployed instance of Token
0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab
Mint
$ npx oz send-tx
? Pick a network development
? Pick an instance Token at 0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab
? Select which function mint(to: address)
? to: address: 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0
✓ Transaction successful. Transaction hash: 0x40f3bf5d44b482d2f89ca8ab5adcf451f0511c156db894081a20915659b48563
Events emitted:
- Transfer(0x0000000000000000000000000000000000000000, 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0, 1)
Mint (reverts when not minter)
$ npx oz send-tx --from 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0
? Pick a network development
? Pick an instance Token at 0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab
? Select which function mint(to: address)
? to: address: 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0
✖ Calling: 'mint' with:
- to (address): "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0"
Error while trying to send transaction to 0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab.
Error: Returned error: VM Exception while processing transaction: revert Token: account does not have minter role