Implementing NFT royalty fees directly in smart contract code

I’m working on creating an NFT collection and want to implement royalty payments directly within my Solidity smart contract. I don’t want to rely on marketplace-specific royalty systems since they can be unreliable.

I’m building my project using a scaffold framework for Ethereum development. What’s the best approach to embed royalty functionality into the contract itself? Should I use EIP-2981 standard or are there other methods?

I want to ensure that creators get paid royalties on secondary sales regardless of which platform the NFTs are traded on. Any code examples or guidance would be really helpful for implementing this properly.

totally agree! EIP-2981 works for legit platforms, but ya gotta be smart about your code. those gas fees are a killer tho. operator filter is the way to go for broad coverage on sales. let’s hope that keeps things fair for creators!

Hey @DancingCloud! Cool project. I’ve been wrestling with royalty enforcement too - it’s a nightmare.

Here’s the thing though - how do you stop someone from just using transferFrom() directly? They can bypass your royalty function completely, and there’s no way to prevent that at the contract level.

What’s your experience with different marketplaces? OpenSea basically gave up on creator royalties unless you use operator filtering, but I’m not convinced those solutions actually work long-term.

EIP-2981 is great for declaring royalties, but enforcement is where everything falls apart. You thinking about an allowlist for approved marketplaces? Or some other mechanism?

Which scaffold are you using? That’ll probably affect your best approach. Also, have you checked out any of the newer enforcement tools? I’d love to know more about your use case and expected trading volume.

I used EIP-2981 on my last NFT project. Works great for compliant marketplaces, but you can’t stop direct transfers - that’s just reality. The standard’s pretty simple - override the royaltyInfo function with your fee percentage and recipient address. I paired it with a custom transfer hook that calculates and sends royalties before completing sales. You’ll need to distinguish real sales from regular transfers though, which gets messy. I went with whitelisting known marketplace contracts. Honestly, the code isn’t the hard part - it’s adoption. Someone can always build a marketplace that ignores your royalties completely. Better to make it dead simple for good actors to comply than waste time trying to force bad actors. Most legit platforms will respect EIP-2981 if you implement it right.