1

Just a quick question regarding an error in my code. I am getting a indexed expression needs to be a type, mapping, or array error for the code I posted below. I am very confused. I tried to create a mapping for this variable and it didnt seem to solve the problem. I also declared the variable in the global scope and still nothing changed. A bit confused here.

    //a function that allows a user to list their NFTs. No need to create a minting 
     function as ERC1155 implements the function already
     
     function listNFT(
     uint nftId, 
     uint priceOfNft
     ) 
     external 
   {
      require (balanceOf[msg.sender] > 0, "Not enough funds to list NFT");
      require (priceOfNft[nftId] >= 0, "Listing price must be greater than 0");

        if(balanceOf[msg.sender] <= 0){

           revert("Funds not sufficient enough to list NFT");
       }


        if(priceOfNft[nftId] <= 0){
        revert("Listing price must be greater than 0");
       }

       balanceOf[msg.sender] += amountOfNfts;
       tokenSupply.increment();

       tokenId = nftId;

       emit nftListed(tokenId, owner, priceOfNft);
    }
2
  • you have uint priceOfNft in function argument and priceOfNft[nftId] in the code, did you shadow some global variables with the same name ?
    – minhhn2910
    Commented Sep 14, 2023 at 18:20
  • i actually fixed that issue. So the array that I define within the function is supposed to be a different name compared to the arguements?
    – EGstacking
    Commented Sep 14, 2023 at 18:41

0

Your Answer

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

Browse other questions tagged or ask your own question.