-
-
Save shobhitic/50518080ca7cb29072d72730873ff54a to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "@openzeppelin/[email protected]/access/Ownable.sol"; | |
contract MyToken is ERC721, ERC721Enumerable, Ownable { | |
string public contractURI; | |
uint96 royaltyFeesInBips; | |
address royaltyAddress; | |
constructor(uint96 _royaltyFeesInBips, string memory _contractURI) ERC721("MyToken", "MTK") { | |
royaltyFeesInBips = _royaltyFeesInBips; | |
royaltyAddress = owner(); | |
contractURI = _contractURI; | |
// setRoyaltyInfo(msg.sender, _royaltyFeesInBips); | |
} | |
function safeMint(address to, uint256 tokenId) public onlyOwner { | |
_safeMint(to, tokenId); | |
} | |
function setRoyaltyInfo(address _receiver, uint96 _royaltyFeesInBips) public onlyOwner { | |
royaltyAddress = _receiver; | |
royaltyFeesInBips = _royaltyFeesInBips; | |
} | |
function setContractURI(string calldata _contractURI) public onlyOwner { | |
contractURI = _contractURI; | |
} | |
// The following functions are overrides required by Solidity. | |
function _beforeTokenTransfer(address from, address to, uint256 tokenId) | |
internal | |
override(ERC721, ERC721Enumerable) | |
{ | |
super._beforeTokenTransfer(from, to, tokenId); | |
} | |
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) | |
external | |
view | |
virtual | |
override | |
returns (address, uint256) | |
{ | |
return (royaltyAddress, calculateRoyalty(_salePrice)); | |
} | |
function calculateRoyalty(uint256 _salePrice) pure public returns (uint256) { | |
return (_salePrice / 10000) * royaltyFeesInBips; | |
} | |
function supportsInterface(bytes4 interfaceId) | |
public | |
view | |
override(ERC721, ERC721Enumerable) | |
returns (bool) | |
{ | |
return interfaceId == 0x2a55205a || super.supportsInterface(interfaceId); | |
} | |
} |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/common/ERC2981.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol"; | |
contract MyToken is ERC721, ERC721Enumerable, ERC2981, Ownable { | |
string public contractURI; | |
constructor(uint256 _royaltyFeesInBips, string memory _contractURI) ERC721("MyToken", "MTK") { | |
setRoyaltyInfo(owner(), _royaltyFeesInBips); | |
contractURI = _contractURI; | |
} | |
function safeMint(address to, uint256 tokenId) public onlyOwner { | |
_safeMint(to, tokenId); | |
} | |
function setRoyaltyInfo(address _receiver, uint96 _royaltyFeesInBips) public onlyOwner { | |
_setDefaultRoyalty(_receiver, _royaltyFeesInBips); | |
} | |
function setContractURI(string calldata _contractURI) public onlyOwner { | |
contractURI = _contractURI; | |
} | |
// The following functions are overrides required by Solidity. | |
function _beforeTokenTransfer(address from, address to, uint256 tokenId) | |
internal | |
override(ERC721, ERC721Enumerable) | |
{ | |
super._beforeTokenTransfer(from, to, tokenId); | |
} | |
function supportsInterface(bytes4 interfaceId) | |
public | |
view | |
override(ERC721, ERC721Enumerable, ERC2981) | |
returns (bool) | |
{ | |
return super.supportsInterface(interfaceId); | |
} | |
} |
@arkaydeus good catch, fixed it, thanks!
Line 60 of the first example above has an extra ) at the end than there should be.
what the difference between both of the contracts?
get at ERC2981NFTCustom.sol
can someone please help
an error:
DeclarationError: Function with same name and parameter types defined twice.
--> contracts/ERC2981NFTdrawo.sol:43:5:
|
43 | function supportsInterface(bytes4 interfaceId)
| ^ (Relevant source part starts here and spans across multiple lines).
Note: Other declaration is here:
--> contracts/ERC2981NFTdrawo.sol:67:5:
|
67 | function supportsInterface(bytes4 interfaceId)
| ^ (Relevant source part starts here and spans across multiple lines).
TypeError: Function has override specified but does not override anything.
--> contracts/ERC2981NFTdrawo.sol:57:9:
|
57 | override
| ^^^^^^^^
@logistic-people-deutschland on ERC2981NFTCustom.sol
file there are supportsInterface
function twice, so remove it the last one and should work
what the difference between both of the contracts?
@Nir-Cohen one uses Openzeppelin's implementation and one is custom. Accompanying video - https://www.youtube.com/watch?v=h6Fb_dPZCd0
Hi, sir. I have add setRoyaltyInfo to my ERC2981 contract, but it doesn't work.
contract ALPHA is ERC721Enumerable, ERC2981, Ownable{
constructor()
ERC721("ALPHA Coin", "ALPHA")
{
manager = msg.sender;
// set royalty of all NFTs to 10%
_setDefaultRoyalty(manager, 1000);
}
}
sir, the Creator Fees doesn't show on test opensea, is that right?
line 13 on constructor _royaltyFeesInBips should be uint96
what about an ERC1155 implementation?
_setDefaultRoyalty takes a uint96 for the second argument so i think line 22 needs to change _royaltyFeesInBips to uint96 from uint256