0

I have a mapping which maps uniqueids to an array of structs called Listing:

mapping(uint256 => Market.Listing[]) private _listings; 

// the struct in the Market.sol
struct Listing {
   address[] nftContract;
   uint256[] tokenId;
   uint256[] price;
}

In my function I am trying to perform some checks. First whether they own the NFT and second whether the address in the struct is set (it is zero if not listing in the market) like so:

const INTERFACE_ID_721 = 0x80ac58cd;

function list(address nftContract, uint256 tokenId, uint256 price) public payable nonReentrant {
    if (IERC165(nftContract).supportsInterface(INTERFACE_ID_721)) {
       require(IERC721(nftContract).ownerOf(tokenId) == msg.sender, "Not owner of nft");
       require(_listings[uid][0].nftContract == address(0), "NFT already listed");
       // do more stuff here..
    }
}

Ive tried to reference the first element:

if (IERC165(nftContract).supportsInterface(INTERFACE_ID_721)) {
   Market.Listing memory listing = _listings[uid][0];
   require(IERC721(nftContract).ownerOf(tokenId) == msg.sender, "Not owner of nft");
   require(listing .nftContract == address(0), "NFT already listed");
   // do more stuff here..
}

But with the above I arrive with a similar error "Operator == Not compatible with types address[] memory and address".

1 Answer 1

0

If I am correct, the error is in line require(listing .nftContract == address(0), "NFT already listed");. As I can see, what you did is create an instance of a struct element in the variable listing and tried to compare the data of listing.nftContract with an address(0).

If you see your struct, the nftContract is actually an array of addresses. Thus, the error. You are trying to compare the array of addresses with a single zero address, which doesn't make any sense. You have to find another way to achieve your goal. Maybe another mapping, like this:

require(isContractALreadyListed[nftContract] == false, "NFT already listed");
2
  • Id prefer not to change the mapping. The market contract works as is with 721 and other standards but I had to make it an array to accompany compatibility with ERC1155 as it is one tokenid to many addresses. So 1155 is what motivated me to changed it to an array of addresses and tokenids within the Struct
    – Potion
    Nov 30, 2022 at 6:21
  • Never mind I resolved it using the following structure which mimics the array in the original design mapping(uint256 => mapping(uint256 => Market.Listing)) private _listings;
    – Potion
    Nov 30, 2022 at 6:39

Your Answer

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

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