Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting royalties as per EIP2981 / ERC2981 #301

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion smart-contract/contracts/YourNftToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import 'erc721a/contracts/ERC721A.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/cryptography/MerkleProof.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/token/common/ERC2981.sol';

contract YourNftToken is ERC721A, Ownable, ReentrancyGuard {
contract YourNftToken is ERC721A, ERC2981, Ownable, ReentrancyGuard {

using Strings for uint256;

Expand Down Expand Up @@ -38,6 +39,26 @@ contract YourNftToken is ERC721A, Ownable, ReentrancyGuard {
maxSupply = _maxSupply;
setMaxMintAmountPerTx(_maxMintAmountPerTx);
setHiddenMetadataUri(_hiddenMetadataUri);
// ERC2981: set default royalty
_setDefaultRoyalty(address(this), 500);
}

/// @dev Sets token royalties
/// @param receiver of the royalties
/// @param value percentage ((using 2 decimals - 10000 = 100%, 500 = 5%, 0 = 0)
function setRoyalties(address receiver, uint96 value) public onlyOwner {
require(receiver != address(0), "ERC2981: invalid receiver");
require(value <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");

_setDefaultRoyalty(receiver, value);
}

/**
* @dev This function shows the interfaces supported by the contract
*/
function supportsInterface(bytes4 interfaceId) public view override(ERC2981, ERC721A) returns (bool) {
return ERC2981.supportsInterface(interfaceId) ||
ERC721A.supportsInterface(interfaceId);
}

modifier mintCompliance(uint256 _mintAmount) {
Expand Down