[Ethereum] I couldn’t make ERC2981 royalties work

dappsethereum-wallet-dappremixsolidity

I have implemented royalty function to my ERC721 NFT smart contract. When I deploy my contract, royalty contract is equal to my address so this way I have defined which address the royalties get transferred.

Secondly, I have set my percentage to 3. Minting cost is 2.50 eth, so whenever people sell their NFT I should get the %3 percentage which equals to 0,075 eth but I don't. I can see that when I call royaltyInfo function in Remix with tokenID, receiver is owner's address and the value is 0,075 eth in wei.

Then I deploy my contract to rinkeby, mint few tokens with another address, sell them to another address on OpenSea but the contract owner's balance does not go up, nor does contract's balance.

There are my codes. By the way, I get that warning but I don't understand how do I place _tokenId there, it gives me error whenever I try to do that.

enter image description here

uint256 public royaltyPerc = 3;
    uint256 public cost = 2.50 ether;
    address payable public royaltyContract;
    bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;
    
    
    constructor (
        string memory _name,
        string memory _symbol,
        string memory _initBaseURI
        ) ERC721(_name, _symbol) {
            
            royaltyContract = payable(msg.sender);
            setBaseURI(_initBaseURI);
            mint(msg.sender, 1);
            
        }
        
        // public
        function mint(address _to, uint256 _mintAmount) public payable {
            uint256 supply = totalSupply();
            require(!paused);
            require(_mintAmount > 0);
            require(_mintAmount <= maxMintAmount);
            require(supply + _mintAmount <= maxSupply);
            
            for (uint256 i = 1; i <= _mintAmount; i++) {
                _safeMint(_to, supply + i);
            }
            
        }
        
        function setRoyaltyPercent ( uint256 _perc ) public onlyOwner {
            royaltyPerc = _perc;
        }

        function royaltyInfo( uint256 _tokenId, uint256 _salePrice ) public  view returns ( address receiver, uint256 royaltyAmount ) {
            receiver = royaltyContract;
            royaltyAmount = _salePrice * royaltyPerc / 100;
        }

I also tried to find another example to try and see where I'm wrong, but I have no idea where these "recipient" and "value" values from as we don't assign them.

enter image description here

Best Answer

The royalties set via ERC-2981 is designed to be paid by buyer/seller voluntarily.

It is the job of MarketPlace to handle royalty. As far as i know, OpenSea test-net does not support ERC2-981.

Modifying transfer function is one way to enforce owner/artist fee on each transfer, but there are some problems using this approach.

  • There is no way to detect if a transfer is a trade on some marketplace or just the user transferring token between own wallets.
  • If somehow we detect that a transfer is a trade, then the problem is we do not know the the price of trade in our transfer method.
Related Topic