[SOLVED] Unable to call Moralis.executeFunction - Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'match')

I’m following the docs here: https://docs.moralis.io/moralis-server/web3/web3#executefunction

I’ve successfully connected to the wallet, and initialized Web3 (and validated using the example here:https://docs.moralis.io/moralis-server/web3/web3#ensureweb3isinstalled).

However, whenever I try to execute any function, I get the below error:

custom.js:46 Activated
moralis.js:7270 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘match’)
at Function. (moralis.js:7270:51)
at tryCatch (moralis.js:73891:40)
at Generator.invoke [as _invoke] (moralis.js:74122:22)
at Generator.next (moralis.js:73947:21)
at asyncGeneratorStep (moralis.js:30483:24)
at _next (moralis.js:30505:9)
at moralis.js:30512:7
at new Promise ()
at new Wrapper (moralis.js:57078:24)
at Function. (moralis.js:30501:12)
(anonymous) @ moralis.js:7270
tryCatch @ moralis.js:73891
invoke @ moralis.js:74122
(anonymous) @ moralis.js:73947
asyncGeneratorStep @ moralis.js:30483
_next @ moralis.js:30505
(anonymous) @ moralis.js:30512
Wrapper @ moralis.js:57078
(anonymous) @ moralis.js:30501
(anonymous) @ moralis.js:7438
mintToken @ custom.js:66

Here’s the code:

const options = {

        address: '0x3d2B7cA35F9d442d491a0649a71d6A822462C84C',

        function_name: 'totalSupply',

        abi: ABI

      };

     

      const transaction = await Moralis.executeFunction(options);

      const receipt = await transaction.wait();

      console.log(receipt);

Originally I tried a write function, which threw the same error:

const options = {

        chain: "mumbai",

        address: "0x3d2B7cA35F9d442d491a0649a71d6A822462C84C",

        function_name: "publicMint",

        abi: ABI,

        params: {},

        msgValue: "10000000000000000"

      };

you don’t need to specify the chain as it’ll be calling to the chain your wallet is connected to.

and it should be functionName and contractAddress based on the docs https://docs.moralis.io/moralis-server/web3/web3#executefunction

That’s what I thought, so that’s why my first example is stripped down to just the ABI, function name, and contract address like this (tried both with single and double quotes):

const options = {

        address: "0x3d2B7cA35F9d442d491a0649a71d6A822462C84C",

        function_name: "totalSupply",

        abi: ABI

      };

     

      const transaction = await Moralis.executeFunction(options);

I was just giving the example of what I started with, but even a simple read only call is failing.

try

      const options = {
        contractAddress:"0x3d2B7cA35F9d442d491a0649a71d6A822462C84C",
        functionName: 'totalSupply',
        abi: ABI
      }

as @YosephKS suggested :woman_mage:

:man_facepalming: I get it now… I was using the old documentation/examples for the address/function_name parameters. That worked, thank you so much!

1 Like

Im’ having similar error, but with Contract. My Options are all correct / no typos…

1 Like