Hey everyone, I’m trying to figure out how to add royalties to my NFT marketplace using ERC2981. I’ve looked at some posts about it but I’m still confused.
Can someone explain what the feeNumerator is in _setDefaultRoyalty(address receiver, uint96 feeNumerator)? Is it the NFT price or the royalty percentage?
I’ve got a contract for minting and listing NFTs, but I’m not sure if I’m handling the royalties correctly. Here’s a simplified version of what I’ve got:
contract AudioNFT is ERC721URIStorage, ERC2981, Ownable {
struct Track {
address creator;
address owner;
string name;
string description;
uint256 price;
uint256 royaltyPercent;
uint256 id;
bool isListed;
}
mapping(uint256 => Track) public tracks;
function mintTrack(string memory uri, string memory name, string memory description, uint256 price, uint256 royaltyPercent) public returns(uint256) {
// Minting logic here
}
function listTrack(uint256 trackId) public {
// Listing logic here
_setDefaultRoyalty(tracks[trackId].creator, uint96(tracks[trackId].royaltyPercent));
}
}
Am I on the right track? Any help would be appreciated!
hey jade75! i’ve been playing around with erc2981 too, it’s pretty cool stuff
youre on the right track, but there’s a small thing to watch out for with the feeNumerator. it’s actually a fraction out of 10000, not a direct percentage. so if you want a 2.5% royalty, you’d use 250 as the feeNumerator.
for your contract, you might wanna tweak it a bit:
function mintTrack(...) public returns(uint256) {
// your minting logic
uint256 tokenId = // however you're generating the id
_setTokenRoyalty(tokenId, msg.sender, uint96(royaltyPercent * 100));
// rest of your function
}
this way, each token can have its own royalty rate. and you don’t need to set it again in listTrack.
btw, have you thought about how you’ll handle the royalty payments in your marketplace contract? that’s where the real fun begins!
what kind of audio nfts are you planning? sounds like an interesting project!
Regarding ERC2981 implementation, it’s crucial to understand that the feeNumerator represents basis points, not direct percentages. For a 2.5% royalty, you’d use 250 as the feeNumerator (250/10000 = 2.5%).
Your approach is close, but consider setting royalties during minting instead of listing. This ensures each token has its royalty rate from the start:
For the marketplace contract, you’ll need to implement royalty calculations and transfers during sales. Ensure you’re using royaltyInfo() to get the correct royalty amounts for each transaction.