Hi @rofflman,
Again, your words are appreciated. For the Space Shooter I used an already deployed contract which it was not verified, true. And yes, If I remember well itās the same or very similar to the one used in AngryBirds project:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
// deployed to Mumbai at 0x698d7D745B7F5d8EF4fdB59CeB660050b3599AC3
contract GameNfts is ERC1155, ERC1155Holder, AccessControl, Pausable {
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
//bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
mapping(uint256 => string) _tokenUrls;
constructor() ERC1155("URI NOT SET") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(URI_SETTER_ROLE, msg.sender);
_grantRole(PAUSER_ROLE, msg.sender);
//_grantRole(MINTER_ROLE, msg.sender);
}
function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) {
_setURI(newuri);
}
function pause() public onlyRole(PAUSER_ROLE) {
_pause();
}
function unpause() public onlyRole(PAUSER_ROLE) {
_unpause();
}
function mint(address account, uint256 id, uint256 amount, string memory url, bytes memory data)
public //override
//onlyRole(MINTER_ROLE)
{
_mint(account, id, amount, data);
_tokenUrls[id] = url;
}
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, string[] memory urls, bytes memory data)
public //override
//onlyRole(MINTER_ROLE)
{
require(ids.length == urls.length, "Each id requires a unique url.");
_mintBatch(to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_tokenUrls[ids[i]] = urls[i];
}
}
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
internal
whenNotPaused
override(ERC1155)
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
// The following functions are overrides required by Solidity.
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC1155, ERC1155Receiver, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256 id) public view virtual override returns (string memory) {
return _tokenUrls[id];
}
}
As you can see I commented āMINTER ROLEā parts as this is a tutorial and thereās no need for setting up AccessControl for users but remember you would need to do that if youāre planning to go in to production.
Cheers