Question
Hey, I deployed a upgradable ERC1155 smart contact with access control. I believe that have necessaey knowleade about 'Access Contol' such as reson behind DEFAULT_ADMIN_ROLE, roleAdmin, etc. I assigned a role 'MINTER_ROLE' to some functions to restrict access and i also grant 'MINTER_ROLE' role to an specific address in constructor. But when i tried to access the function(which has access only by the address with 'MINTER_ROLE') with 'MINTER_ROLE' in etherscan i got an error. then i tried the same thing in remix it works well without any error.
ERROR MESSAGE GOT IN SEPOLIA ETHERSCAN:
Error: execution reverted: AccessControl: account 0x0000000000000000000000000000000000000000 is missing role 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6 { "originalError": { "code": 3, "data": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000094416363657373436f6e74726f6c3a206163636f756e7420307830303030303030303030303030303030303030303030303030303030303030303030303030303030206973206d697373696e6720726f6c6520307839663264663066656432633737363438646535383630613463633530386364303831386338356238623861316162346365656566386439383163383935366136000000000000000000000000", "message": "execution reverted: AccessControl: account 0x0000000000000000000000000000000000000000 is missing role 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6" } }
NOTE: 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6 is an encode output of keccal256("MINTER_ROLE")
After i grant access to zero address to 'MINER_ROLE' the function works properly.
My Question is "Why Zero Adderss(0x0000000000000000000000000000000000000000) need access to the function in seoplia etherscan?
Code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155URIStorageUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract MAURewards is
Initializable,
ERC1155Upgradeable,
AccessControlUpgradeable,
ERC1155URIStorageUpgradeable,
UUPSUpgradeable
{
bytes32 private constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
uint256 private numOfRewards;
mapping(uint256 => uint256) private _totalSupply;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize() public initializer {
__ERC1155_init("https://www.arweave.net/");
__AccessControl_init();
__UUPSUpgradeable_init();
_setBaseURI("https://www.arweave.net/");
_grantRole(
DEFAULT_ADMIN_ROLE,
0xcC4351eF0555f636A46DaaF82BEfa8F801D50155
);
_grantRole(MINTER_ROLE, msg.sender);
_grantRole(UPGRADER_ROLE, msg.sender);
}
function setNumOfRewards(
uint256 _numOfRewards
) public onlyRole(MINTER_ROLE) {
numOfRewards = _numOfRewards;
}
function getNumOfRewards()
public
view
onlyRole(MINTER_ROLE)
returns (uint256)
{
return numOfRewards;
}
function setTokenEndpointURI(
uint256 tokenId,
string memory tokenEndpointURI
) public onlyRole(MINTER_ROLE) {
require(
tokenId < numOfRewards,
"You can't set Endpoint to this Reward, Because Reward does not exist"
);
_setURI(tokenId, tokenEndpointURI);
}
function uri(
uint256 tokenId
)
public
view
virtual
override(ERC1155Upgradeable, ERC1155URIStorageUpgradeable)
returns (string memory)
{
return ERC1155URIStorageUpgradeable.uri(tokenId);
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal override {
require(
from == address(0),
"You can't transfer the Token, Because it is SBT"
);
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i];
}
}
}
function safeMint(
address account,
uint256 id,
uint256 amount,
bytes memory data
) public onlyRole(MINTER_ROLE) {
require(
id < numOfRewards,
"You can't mint this Reward, Because Reward does not exist"
);
_mint(account, id, amount, data);
}
function mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public onlyRole(MINTER_ROLE) {
_mintBatch(to, ids, amounts, data);
}
function totalSupply(
uint256 id
) public view onlyRole(MINTER_ROLE) returns (uint256) {
return _totalSupply[id];
}
function exists(
uint256 id
) public view onlyRole(MINTER_ROLE) returns (bool) {
return id < numOfRewards;
}
function _authorizeUpgrade(
address newImplementation
) internal override onlyRole(UPGRADER_ROLE) {}
// The following functions are overrides required by Solidity.
function supportsInterface(
bytes4 interfaceId
)
public
view
override(ERC1155Upgradeable, AccessControlUpgradeable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
Additional Details
Contract: ERC1155 UUPS Upgradable Contact
Problem: In Access Control
Network: Sepolia Testnet
Etherscan: Got Error
Remix IDE: Works well. without error