Royalty
In this tutorial you'll continue building your non-fungible token (NFT) smart contract, and learn how to implement perpetual royalties into your NFTs. This will allow people to get a percentage of the purchase price when an NFT is sold.
Introduction
By now, you should have a fully fledged NFT contract, except for the royalties support.
To get started, go to the nft-contract-approval/
folder from our GitHub repository, or continue your work from the previous tutorials.
cd nft-contract-approval/
If you wish to see the finished code for this Royalty tutorial, you can find it in the nft-contract-royalty
folder.
Thinking about the problem
In order to implement the functionality, you first need to understand how NFTs are sold. In the previous tutorial, you saw how someone with an NFT could list it on a marketplace using the nft_approve
function by passing in a message that could be properly decoded. When a user purchases your NFT on the marketplace, what happens?
Using the knowledge you have now, a reasonable conclusion would be to say that the marketplace transfers the NFT to the buyer by performing a cross-contract call and invokes the NFT contract's nft_transfer
method. Once that function finishes, the marketplace would pay the seller for the correct amount that the buyer paid.
Let's now think about how this can be expanded to allow for a cut of the pay going to other accounts that aren't just the seller.