Last active
August 15, 2023 16:23
ERC-2981 compliant ERC-1155 smart contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.17; | |
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | |
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/token/common/ERC2981.sol"; | |
contract RoyaltyContract is ERC1155, ERC1155Supply, Ownable, ERC2981 { | |
string public name; | |
string public symbol; | |
constructor( | |
string memory initialUri, | |
uint96 feeNumerator, | |
address receiver, | |
string memory _name, | |
string memory _symbol | |
) ERC1155(initialUri) { | |
_setDefaultRoyalty(receiver, feeNumerator); | |
name = _name; | |
symbol = _symbol; | |
} | |
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, ERC2981) returns (bool) { | |
return super.supportsInterface(interfaceId); | |
} | |
function setURI(string memory newuri) | |
public | |
onlyOwner | |
{ | |
_setURI(newuri); | |
} | |
function mint(uint256 amount, uint256 tokenId) | |
external | |
payable | |
{ | |
require(amount > 0, "Must mint at least 1 NFT"); | |
_mint(msg.sender, tokenId, amount, ""); | |
} | |
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) external { | |
_mintBatch(to, ids, amounts, data); | |
} | |
function _beforeTokenTransfer( | |
address operator, | |
address from, | |
address to, | |
uint256[] memory ids, | |
uint256[] memory amounts, | |
bytes memory data | |
) | |
internal | |
override(ERC1155, ERC1155Supply) | |
{ | |
super._beforeTokenTransfer(operator, from, to, ids, amounts, data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment