From a7dbbd60a750f220e90e8c37c0ac1cd15e117a40 Mon Sep 17 00:00:00 2001 From: Zods <104772831+it-is-zods@users.noreply.github.com> Date: Fri, 27 May 2022 21:48:33 +0100 Subject: [PATCH 1/2] Setting royalties as per EIP2981 / ERC2981 a small tweak to implement EIP2981 to set royalties. I understand it is up to the marketplace to honour it (e.g. OpenSea and Rarible have their own "hack" for royalties) but it seems the EIP2981 is starting to be adopted by newer marketplaces and hopefully the dinosaurs will eventually follow. these changes are small and hopefully make this contract future proof as per Liarco suggestion, I've created a way to set royalties at any time, but have a default open in the construct *note: I've only used this in a couple of test contracts, so please do your own tests and submit any feedback and/or tweaks here --- smart-contract/contracts/YourNftToken.sol | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/smart-contract/contracts/YourNftToken.sol b/smart-contract/contracts/YourNftToken.sol index 20f00c5ba..8b530c863 100644 --- a/smart-contract/contracts/YourNftToken.sol +++ b/smart-contract/contracts/YourNftToken.sol @@ -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; @@ -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) { From 5b7929aad051659211f4a9b681b467ef1ec7668f Mon Sep 17 00:00:00 2001 From: Zods <104772831+it-is-zods@users.noreply.github.com> Date: Sat, 28 May 2022 21:00:49 +0100 Subject: [PATCH 2/2] Update YourNftToken.sol small typo, was missing the _ --- smart-contract/contracts/YourNftToken.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart-contract/contracts/YourNftToken.sol b/smart-contract/contracts/YourNftToken.sol index 8b530c863..705e306fb 100644 --- a/smart-contract/contracts/YourNftToken.sol +++ b/smart-contract/contracts/YourNftToken.sol @@ -40,7 +40,7 @@ contract YourNftToken is ERC721A, ERC2981, Ownable, ReentrancyGuard { setMaxMintAmountPerTx(_maxMintAmountPerTx); setHiddenMetadataUri(_hiddenMetadataUri); // ERC2981: set default royalty - setDefaultRoyalty(address(this), 500); + _setDefaultRoyalty(address(this), 500); } /// @dev Sets token royalties