Skip to content

Instantly share code, notes, and snippets.

@andy8052
Created October 30, 2022 20:50
Show Gist options
  • Save andy8052/972ee680aadc7951d4ce6f93516b4a94 to your computer and use it in GitHub Desktop.
Save andy8052/972ee680aadc7951d4ce6f93516b4a94 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "openzeppelin/token/ERC1155/ERC1155.sol";
import "openzeppelin/access/AccessControl.sol";
import "openzeppelin/security/Pausable.sol";
contract AccessSBT is ERC1155, AccessControl, Pausable {
constructor() ERC1155("") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_mint(msg.sender, uint256(DEFAULT_ADMIN_ROLE), 1, "0x0");
_pause();
}
function setURI(string memory newuri) public onlyRole(DEFAULT_ADMIN_ROLE) {
_setURI(newuri);
}
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
_unpause();
_mint(account, uint256(role), 1, "0x0");
}
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
_unpause();
_burn(account, uint256(role), 1);
}
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
internal
whenNotPaused
override
{
_pause();
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
// The following functions are overrides required by Solidity.
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC1155, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment