0

I am working on NFT Smart Contract using ERC-1155. So when i list the item for fixedPrice Selling , i have to provide the address of RoyaltyRecipient to whom the royalty would be transfered.This RoyaltyRecipient field have to accept the address of only of the minter , who has minted the NFT. any address other than the minter is placed inside it , it should says , you are not the minter.

This is my code

function listItemForFixedPrice(uint256 _tokenId, uint256 _amount , uint256 _price , uint256 _royaltyFee, address _nftAddress , address _royaltyRec)public  OnlyTokenHolders(_tokenId , _nftAddress) returns(uint256)
    {
        require(_tokenId >= 0 , "TokenId can not be negative integer");
        require(_amount > 0 , "amount of nfts can not be zero");
        require(_price > 0.0001 ether  , "Price should be greater than 10 ether");
        require(_nftAddress != address(0), "NFT address cannot be 0x0000000000000000000000");
        require(_royaltyFee <= 2000 && _royaltyFee >= 150 , "Royalties fee can not be greater than 20% ");


        uint256 newItemId = Fixedprices.length;
        Fixedprices.push(FixedPrice(false,true,msg.sender,address(0),_nftAddress, _royaltyRec,_price,0,newItemId,_tokenId,_royaltyFee,_amount));
        IERC1155(_nftAddress).safeTransferFrom(msg.sender,address(this), _tokenId, _amount, "0x00");    

        emit OfferSale(newItemId);
        return newItemId;   
    }

1 Answer 1

0

You create a mapping, everytime a mint happens store the minter of token Id in nftArtist -

mapping(uint => address) nftArtist;

In your listItemForFixedPrice() function, add below check -

function listItemForFixedPrice(uint256 _tokenId, uint256 _amount , uint256 _price , uint256 _royaltyFee, address _nftAddress , address _royaltyRec)public  OnlyTokenHolders(_tokenId , _nftAddress) returns(uint256)
{
    ...
    require(_royaltyRec == nftArtist[_tokenId], "Royalty receiver is not valid");
    ...
}
2
  • what if i want to call this require check from another contract
    – Umar Raza
    Sep 19, 2022 at 3:38
  • @UmarRaza you will need to create a public function in the contract where you have nftArtist. That function will give access to other contracts to read state variables of the primary contract.
    – DIGVJSS
    Sep 20, 2022 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.