Solidity ERC721 – How to Distribute Royalties to Addresses with an ERC721

erc-721smart-contract-walletssolidity

I was thinking about a use case let's say that we have a deployed smart contract ERC721 with 100 NFTS all of them minted. and I want to send to these 100 addresses royalties?

How can approach that? should I use PaymentSplitter?

Can you share please any resources or an example of a smart contract that can do that?

Thank you

Best Answer

you can do it manually, by creating a batch transfer kind of function that looks like this: function sendRoyalties(address[] calldata _nftHolders, uint amountToSend) external;

or you can create a Custom Method:

  1. You can create a custom contract where all the royalties will be sent.
  2. You should then implement a function that allows anyone that has an NFT to claimRoyalties()
  3. this function will check if the user has an NFT from your collection, will send the royalties and update (ideally a mapping) its claimable Royalties so that they can no longer claim or whatever conditions you want.

It should check if the caller has an NFT, and under the hood:

  • it should then update a mapping(uint => uint) for tokenId => amountClaimed Example: 100 ETH royalties 100 / 100 = 1 ETH

UserA holder of TokenID "99" claims 1 ETH

mapping is equal to (99 => 1 ETH);

  • after a while 100 more ETH are added to the smart contract

  • UserB holder of TokenID 11, can claim (200 / 100) = 2 ETH

  • UserA holder of TokenID 99 can claim (200 / 100) = 2 ETH - 1 ETH (already claimed and visible on mapping)

claimableRoyalties[99] == 1 ETH, before the claim

claimableRoyalties[99] == 2 ETH, after the claim

Related Topic