Cannot read properties of undefined (reading 'match')

Hey devs what could be reason of this error when interacting with smart contract?
Cannot read properties of undefined (reading ‘match’)

I’m trying to interact with SC when i invoke the function it returns only this error

here is my function

// SMART CONTRACT  CREATE POST
        const createNewPost  =  async ()  =>  {
           // awaitsavePostData()
           let options = {
              contractAddress : "0x60Ae865ee4C725cd04353b5AAb364553f56ceF82",
               abi : LENS_HUB,
                params : {
                vars: {
                  profileId: "0x41cd",
                  contentURI: 'https://ipfs.io/ipfs/Qmby8QocUU2sPZL46rZeMctAuF5nrCc7eR1PPkooCztWPz',
                  collectModule: "0xaeB7E3326e4745639574092801ad5C4467d513c9",
                  collectModuleInitData: "0x0000000000000000000000000000000000000000000000000000000000000001", //defaultAbiCoder.encode(['bool'], [true]),
                  referenceModule: "0x0000000000000000000000000000000000000000",//ZERO_ADDRESS,
                  referenceModuleInitData: [],
                }
               }
            }
          contractExcutor.fetch({
            params: options,

            onSuccess : () => {
              console.log("the post  have  been created  succesfully")
            },

            onError: (error) => {
              console.log(error.message)
            }
          })

        }

I have no idea what I’m doing wrong here ?

Need more details from which script you are getting this error.

And also check if the function name and other values added to the params are not undefined.

the function I’m trying to interact with it has only 5 parameters
1- profileId 2 contentURI, collectModule, collectModuleInitData, referenceModule and referenceModuleData

here is function ABI

  {
       "inputs":[
          {
             "components":[
                {
                   "internalType":"uint256",
                   "name":"profileId",
                   "type":"uint256"
                },
                {
                   "internalType":"string",
                   "name":"contentURI",
                   "type":"string"
                },
                {
                   "internalType":"address",
                   "name":"collectModule",
                   "type":"address"
                },
                {
                   "internalType":"bytes",
                   "name":"collectModuleInitData",
                   "type":"bytes"
                },
                {
                   "internalType":"address",
                   "name":"referenceModule",
                   "type":"address"
                },
                {
                   "internalType":"bytes",
                   "name":"referenceModuleInitData",
                   "type":"bytes"
                }
             ],
             "internalType":"struct DataTypes.PostData",
             "name":"vars",
             "type":"tuple"
          }
       ],
       "name":"post",
       "outputs":[
          {
             "internalType":"uint256",
             "name":"",
             "type":"uint256"
          }
       ],
       "stateMutability":"nonpayable",
       "type":"function"
    },
     :point_right:  

link to function

all params are defined

You did not add the function name in options. It is missing.

1 Like

this solved first problem but i still i get another error Cannot read properties of undefined (reading ‘length’)

where from is that error with length?

I think this was because I forgot to use await when i added this is not returning … length anymore now it throws network does not support ENS (operation=“getResolver”, network=“maticmum”, code=UNSUPPORTED_OPERATION, version=providers/5.6.0)

any clue on how to solve this .

what is this network?

is mumbai testenet network

Solved in profileId was a white space " ID" instead of “ID”

and the error of Cannot read properties of undefined (reading ‘length’) I have no i dea where it cames from tried to double check params but not found anything see my function code here :point_down:

 async function createNewPost ()  {
         let options = {
          contractAddress : "0x60Ae865ee4C725cd04353b5AAb364553f56ceF82",
          functionName : "post",
          abi : LENS_HUB,
          params: {
            vars : {
              profileId: "0x41cd",
             collectModule : "0x0BE6bD7092ee83D44a6eC1D949626FeE48caB30c",
             collectModuleData: defaultAbiCoder.encode(['bool'], [true]),
              referenceModule: ZERO_ADDRESS,
              referenceModuleData: [],
            }
          }
         }

         await contractExcutor.fetch({
          params: options,
          onSuccess : () => {
            console.log("the post  have  been created  succesfully")
          },

          onError: (error) => {
            console.log(error.message)
          }
         }) 
      }

All parameters i followed this documentation :point_right: Smart contract documentation

what is the abi? can you pun only the abi specific to that function?

here is function ABI

{
       "inputs":[
          {
             "components":[
                {
                   "internalType":"uint256",
                   "name":"profileId",
                   "type":"uint256"
                },
                {
                   "internalType":"string",
                   "name":"contentURI",
                   "type":"string"
                },
                {
                   "internalType":"address",
                   "name":"collectModule",
                   "type":"address"
                },
                {
                   "internalType":"bytes",
                   "name":"collectModuleInitData",
                   "type":"bytes"
                },
                {
                   "internalType":"address",
                   "name":"referenceModule",
                   "type":"address"
                },
                {
                   "internalType":"bytes",
                   "name":"referenceModuleInitData",
                   "type":"bytes"
                }
             ],
             "internalType":"struct DataTypes.PostData",
             "name":"vars",
             "type":"tuple"
          }
       ],
       "name":"post",
       "outputs":[
          {
             "internalType":"uint256",
             "name":"",
             "type":"uint256"
          }
       ],
       "stateMutability":"nonpayable",
       "type":"function"
    },
     :point_right:  

link to function

[

this seems like a complex abi, you could try to edit the abi and remove that tuple so that it is a simple abi

Im also facing same issue here is code

          address: DogAdress,
          function_name: 'createCollectible',
          abi: Abi,
          Params: {_tokenURI: url },
        };
        // const price = ethers.utils.parseUnits(formInput.price, 'ether')
        const mint =await Moralis.executeFunction(options)
        console.log(mint)
        await mint.wait()
thats my abi 
```const Abi=  {
          "inputs": [
            {
              "internalType": "string",
              "name": "_tokenURI",
              "type": "string"
            }
          ],
          "name": "createCollectible",
          "outputs": [
            {
              "internalType": "uint256",
              "name": "",
              "type": "uint256"
            }
          ],
          "stateMutability": "nonpayable",
          "type": "function"
        }

You should have your abi as such rather

[
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "_tokenURI",
        "type": "string"
      }
    ],
    "name": "createCollectible",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

ok also Ive a question can we call contract function that require signer to sign a transaction but I dont why this method isnt working with wallet connect in mobile

this function need signer and still getting the same error

What is the error? Does it work in browser with MetaMask?

no jani Im posting whole code

        // const Market = new ethers.Contract(marketplaceAddress, Marketplace.abi, library.getSigner())
        // const Dog = new ethers.Contract(
        //   DogAdress,
        //   NFTDog.abi,
        //   library.getSigner()
        // );
        // // const price = ethers.utils.parseUnits(formInput.price, 'ether')
        // const collectible = await Dog.createCollectible(url);
        const Abi=[
          {
            "inputs": [
              {
                "internalType": "string",
                "name": "_tokenURI",
                "type": "string"
              }
            ],
            "name": "createCollectible",
            "outputs": [
              {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
              }
            ],
            "stateMutability": "nonpayable",
            "type": "function"
          }
        ]

        const options={
        
        address: DogAdress,
        function_name: 'createCollectible',
        abi: Abi,
        Params: {_tokenURI: url },
      };
      // const price = ethers.utils.parseUnits(formInput.price, 'ether')
      const mint =await Moralis.executeFunction(options)
      console.log(mint)
      await mint.wait()
      } else {
        toast.error("O'ops youre missing a field");
        setloading(false);
      }
    } else {
      toast.error("connect wallet or check network");
      setloading(false);
    }
  };```