Royalty Distribution

Implementing Royalty Distribution with ERC-2981 in Bigint NFT Marketplace

Bigint is an on-chain Nft Marketplace. In the realm of digital assets, ensuring creators are fairly compensated for their work is paramount. The Bigint NFT Marketplace leverages the Ethereum Request for Comment (ERC) 2981 standard to facilitate an automated, on-chain royalty distribution mechanism. This guide provides an overview of the ERC-2981 standard and detailed steps for contract owners on how to implement this standard within their NFT contracts to support royalty payments.


What is ERC-2981?

ERC-2981 is a standard interface for Non-Fungible Tokens (NFTs), enabling smart contracts to communicate how much royalty is owed and to whom, whenever an NFT is sold. This standard allows for a standardized way of implementing royalty information directly in the NFT's smart contract, ensuring creators receive their royalties from secondary sales across any platform that supports the ERC-2981 standard.

Benefits of Implementing ERC-2981

  • Standardized Royalties: Simplifies the royalty process across different platforms.

  • Creator Support: Ensures creators continue to receive compensation for their work.

  • Automatic Distribution: Royalties are automatically distributed at the point of sale without requiring manual intervention.

Implementation Guide for Contract Owners

Step 1: Contract Setup

Ensure your NFT contract is ERC-721 or ERC-1155 compliant, as ERC-2981 can be implemented alongside these standards. Here's a simplified example of adding ERC-2981 to an ERC-721 contract:

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

For each NFT, the contract owner or a designated operator must set the royalty information using the setRoyaltyInfo function. This includes the recipient address and the royalty amount (typically a percentage of the sale price).

Testing and Deployment

Before deploying your contract, thoroughly test the royalty distribution mechanism to ensure it works as expected. Consider edge cases, such as very high or very low sale prices, to confirm that the royalty calculation is accurate.

Conclusion

Implementing ERC-2981 in your NFT contracts enhances the value proposition of your digital assets by ensuring creators are fairly compensated. By following the steps outlined above, contract owners can easily integrate this standard, promoting a more sustainable ecosystem for digital creators.

Last updated