Overriding _transfer and _transferFrom function for handling secondary sales royalities of NFT


I wanted to handle royalites of NFT for secondary sales. Initially, I created buyNFT function that will handling royalites and transfer of NFT but later I have been thinking that If someone migrate the NFT to other platform then buyNFT function will not be executed.

I have been thinking to override the _transfer and _transferFrom function and royalities check in it.

Should I do in the same way or is there any other good procedure available?

@abcoathup Please help me out

you have a royalty interface
import "@openzeppelin/contracts/interfaces/IERC2981.sol";

Try to use it

I've seen it. It does enforces to pay royalties. I wanted to work in a way that if NFT can be sold in any marketplace royalties will work

You can override the two functions _beforeTokenTransfer or _afterTokenTransfer, but remember to check the calling conditions.

I don't know if it possible, if a market didn't support royalties what will you do ?