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
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.