Implementing NFT Royalties: A Practical Tutorial on ERC721-C for Artists and Developers
This article was first published on the BuildBear website at Implementing NFT Royalties: A Practical Tutorial on ERC721-C for Artists and Developers (buildbear.io)
What is ERC721-C?
ERC721-C is a new token standard designed for enforceable on-chain royalties. Unlike ERC-721 and ERC1155, ERC721-C makes royalties programmable and allows creators to prevent zero-fee exchanges from listing their works.
Creators can use ERC721-C (and ERC1155-C) to set on-chain royalty rules. This standard enables them to create permissioned smart contracts that control royalty transfers.
With ERC721-C, creators can determine where their NFTs are sold and filter interactions to only approved contracts and applications. This prevents traders from avoiding royalties on zero-fee platforms, as collections created with ERC721-C can opt out of such marketplaces.
How ERC721-C Works
Developers inherit the ERC721-C contract like they would with OpenZeppelin.
They customize or add functionality as needed.
After deploying their ERC721-C collection, developers use the setToDefaultSecurityPolicy() function to point to Limit Break’s Creator Token Transfer Validator contract, applying the default security policy.
The collection then enforces this default transfer policy for all token transfers. Developers can change the policy and/or whitelist anytime for added flexibility.
Programmable Royalties
ERC721-C embeds royalty logic directly into the Ethereum smart contract code, giving creators control over royalties and potentially reducing marketplace dominance.
ERC721-C allows NFT creators to explore different royalty models:
Shared Royalties: Royalties can be split between creators and holders.
Minter-Only Royalties: Only the minter, not the creator, earns royalties.
Contingent Royalties: Royalties apply based on specific criteria, such as sales exceeding the mint price.
Transferable Royalties: Creators can grant holders a separate NFT entitling them to royalty income. For instance, minting “NFT X” might include receiving “NFT Y,”
ERC721 Example with Integrated Programmable Royalties
This example illustrates the integration of programmable royalties into an ERC721 collection, demonstrating the flexibility and ease of use offered by mix-ins. Specifically, we focus on an ERC721-C variant combined with mutable minter royalties, providing an innovative approach to NFT creation and royalty management.
Royalty Management Mix-in: A specialized mix-in enabling minters to retain perpetual royalty rights for the NFTs they create. Critically, this feature allows the original minter to modify the royalty fee for each token ID they have minted, offering unprecedented control and flexibility in the digital art marketplace.
Detailed Breakdown
Imported Contracts:
OwnableBasic.sol
andOwnableInitializable.sol
: Essential contracts that furnish rudimentary ownership control mechanisms, ensuring robust governance over the NFT collection.ERC721C.sol
: A refined version of the standard ERC721 contract, tailored for NFT creation with added functionalities, particularly in security and royalties.MutableMinterRoyalties.sol
: A sophisticated contract managing mutable minter royalties, empowering creators with the ability to adjust royalty configurations dynamically.
Contract Constructor:
Parameters: Receives three critical inputs:
defaultRoyaltyFeeNumerator_
(determining initial royalty fee),name_
(the name of the NFT collection), andsymbol_
(the collection's symbol).Initialization: Sets up the ERC721 foundation with the specified
name
andsymbol
and configures mutable minter royalties using thedefaultRoyaltyFeeNumerator
.
Interface Support Function:
supportsInterface
: An overhauled function to verify support for various interfaces within the contract. This method cross-references functionalities inherited from bothERC721C
andMutableMinterRoyaltiesBase
to ensure comprehensive compatibility.
Token Minting Functions:
mint
: Facilitates the creation of a new token, assigning it a uniquetokenId
and allocating it to a specified address.safeMint
: Functions akin tomint
but incorporates additional safeguards to verify the recipient's ability to receive NFTs, thereby mitigating potential transfer errors.
This comprehensive approach effectively combines the robustness of ERC721 standards with innovative royalty management, offering creators enhanced control and flexibility in the NFT domain.
To help you get started swiftly, we’ve prepared everything at BuildBear Labs ERC721-C.
Cloning or Forking ERC721C:
- Use the following command to clone the ERC721C repository:
git clone https://github.com/BuildBearLabs/ERC721-C.git
Installing Dependencies:
- Change to the ERC721-C directory and install the necessary dependencies:
cd ERC721-C
npm install
Creating Your Private Testnet Fork:
- You can create a private testnet fork from any Testnet or Mainnet, as there’s no need for Mainnet state in this instance:
npm run createTestnet
- After the Testnet is operational, its RPC, Explorer, and Faucet details will be updated in the
testnet.json
file.
Deploying the Contract:
- Once the above steps are completed, execute the following script to deploy your contract.
npx hardhat run .\\scripts\\deploy-ERC721C.js
- Click on the contract link provided in the terminal you will be redirected to the Contract page on the buildbear explorer as shown below
Now, we can directly interact with the contract functions through the explorer. Here’s how to proceed:
Accessing the Faucet:
First, locate the faucet link within the
testnet.json
file.Open the faucet link and utilize the “Add to MetaMask” button to connect your sandbox network to your wallet. This step is essential for minting native tokens, which are necessary to cover gas fees. The process is illustrated below:
Using Contract Write Functions:
Navigate to the ‘Contract Write Function’ section of the explorer.
Connect your wallet, then enter your wallet address and the tokenId.
Proceed to click on the ‘write’ button and confirm the transaction on the explorer. This step is depicted in the image below:
Reading Contract Information:
Move to the ‘Read Contract’ section to verify the owner of the NFT.
Additionally, you can check the royalty fee. For instance, if the NFT’s sale price is 100 ETH, you would receive 10 ETH, which represents 10% of the sale price, as shown in the following example:
Now, let’s proceed to run the test scripts. Conducting tests is essential to verify the functionality and reliability of your contract before deploying it to a live network.
To initiate the testing process, use the following command:
npx hardhat test
Executing this command will run the test scripts specified in the Erc721C-Testnet.js
file. This step is key to ensuring that your contract operates as expected and is free from critical issues prior to its deployment on the blockchain.
Conclusion
ERC721-C offers an effective solution to Web3 royalty challenges. It enables artists to ensure they receive a fixed percentage of sales when their work is resold, by embedding revenue contracts within the NFT’s smart contract.
BuildBearLabs/ERC721-C (github.com)
About BuildBear:
BuildBear is a platform tailored for DApp development and testing. Developers gain the freedom to construct a personalized Private Testnet sandbox across a variety of blockchain networks. The liberty to mint unlimited Native and ERC20 tokens, coupled with rapid transaction times on BuildBear (under 3 seconds!), enhances the DApp development lifecycle manifold. The platform comes equipped with tools designed for real-time testing and debugging, ensuring developers can keep tabs on intricate blockchain transactions with unparalleled ease.
Connect with us on Twitter | LinkedIn | Telegram | GitHub
Author: chandan