I've read already many posts regarding this topic, but I just can't wrap my head around this Royalty implementation thing.
Pls help me out, I don't know how I should play with this thing.
what is feeNumerator? _setDefaultRoyalty(address receiver, uint96 feeNumerator)
is it NFT Price? Nft Royalty Percent?
Pls take a look at the following contract and help me with how I can implement NftRoyalty in this contract. Am I doing it right? if not then pls correct me. Thanks.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.8;
import "hardhat/console.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/common/ERC2981.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract PodShip is ERC721URIStorage, ERC2981, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _podcastId;
Counters.Counter private _nftId;
struct Podcast {
address nftCreator;
address nftOwner;
string nftName;
string nftDescription;
uint256 nftPrice;
uint256 nftRoyaltyPercent;
uint256 nftId;
bool listed;
}
mapping(uint256 => Podcast) podcastId;
constructor() ERC721("PodShip NFTs", "PODSHIP") {}
function mintNft(
string memory ipfsURI,
string memory _nftName,
string memory _nftDescription,
uint256 _nftPrice,
uint256 _nftRoyaltyPercent) public returns(uint256) {
require(_nftPrice > 0, "NFT Price not set correctly");
require(_nftRoyaltyPercent > 0 && _nftRoyaltyPercent <= 50, "NFT Royalty should be in-between 1 & 50");
_podcastId.increment();
_nftId.increment();
uint256 nft_Id = _nftId.current();
_safeMint(msg.sender, nft_Id);
_setTokenURI(nft_Id, ipfsURI);
podcastId[_podcastId.current()] = Podcast(
payable(msg.sender),
payable(msg.sender),
_nftName,
_nftDescription,
_nftPrice,
_nftRoyaltyPercent,
nft_Id,
false
);
console.log(nft_Id);
console.log(_podcastId.current());
return nft_Id;
}
function listNFT(uint256 _podcastID) public {
require(msg.sender == podcastId[_podcastID].nftOwner && msg.sender == podcastId[_podcastID].nftCreator, "Only Owner can list his NFT");
podcastId[_podcastID].listed = true;
approve(address(this), podcastId[_podcastID].nftId);
setApprovalForAll(address(this), true);
_setDefaultRoyalty(podcastId[_podcastID].nftCreator, uint96(podcastId[_podcastID].nftRoyaltyPercent));
}