Add Royalty to solidity NFT smart contract

2.5k Views Asked by At

how can I add royalty to Nft collection at the smart contract level, without using solutions from marketplaces?

I use https://github.com/scaffold-eth this official repo for my task

2

There are 2 best solutions below

1
On BEST ANSWER

The only way to add royalties at the smart contract level without breaking the ER721 Standard is to implement a custom transferFrom function which requires the royalty be paid on every transfer.

This is generally not implemented because it means that users cannot transfer between their wallets without paying the royalty.

There is an EIP around NFT royalties to suggest a standard for defining on-chain royalties, however, marketplaces would still be responsible for enforcing the standard.

If you are not relying on third party marketplaces, then you could add a 'trade' function to your NFT, which implements the logic for an exchange between a currency and the NFT. However, this would not be used by marketplaces like OpenSea and would only be a viable solution if you plan to implement your own marketplace.

0
On

There is EIP-2981 .

The Royalty smart contract from thirdweb is an extension usable with any base smart contract. It implements EIP-2981 NFT royalty standard for royalty support on NFT marketplaces.

But there is another proposal from manifold as well: royalty-registry

It provides the ability for contracts that did not originally support any of the on-chain Royalty specifications to add this functionality to their smart contract. A reference EIP-2981 override implementation can be found here: https://github.com/manifoldxyz/royalty-registry-solidity/blob/main/contracts/overrides/RoyaltyOverride.sol.

Still, market places actually may not use this information. Your smart contract still lets the transfer to happen without the royalty fee. e.g. Sudoswap and now X2Y2 let the seller-buyer decide to pay the royalty fees or not.

To avoid that make a simple tweak to the approval methods in ERC721 that whitelist specific marketplaces: https://gist.github.com/cygaar/6d908d1eb12727d94583ad20b84a06eb