Royalty Distribution
Implementing Royalty Distribution with ERC-2981 in Bigint NFT Marketplace
What is ERC-2981?
Benefits of Implementing ERC-2981
Implementation Guide for Contract Owners
Step 1: Contract Setup
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/interfaces/IERC2981.sol";
contract MyNFT is ERC721, IERC2981 {
// Mapping to store royalty info
mapping(uint256 => RoyaltyInfo) private _royalties;
struct RoyaltyInfo {
address recipient;
uint256 amount;
}
constructor() ERC721("MyNFT", "MNFT") {}
// Implement the ERC-2981 standard function
function royaltyInfo(uint256 tokenId, uint256 salePrice) external view override returns (address, uint256) {
RoyaltyInfo memory royalty = _royalties[tokenId];
return (royalty.recipient, (salePrice * royalty.amount) / 10000);
}
// Function to set royalty info
function setRoyaltyInfo(uint256 tokenId, address recipient, uint256 amount) public {
require(msg.sender == ownerOf(tokenId), "Not the owner");
_royalties[tokenId] = RoyaltyInfo(recipient, amount);
}
}Step 2: Setting Royalty Information
Testing and Deployment
Conclusion
Last updated