{code: 141, error: 'Web3 API error while calling /:address/function'} && TypeError: Cannot read properties of undefined (reading 'call')

Hi guys,

I was attempting to do use the useWeb3ExecuteFunction() react-moralis hook but ran into the error: Cannot read properties of undefined (reading ā€˜callā€™)

So I decided to try and circumvent this issue with useMoralisWeb3Api() and runContractFunction(options)

The call with the options + params etc. seems to work with this method but now I am getting {code: 141, error: 'Web3 API error while calling /:address/function'} as a error

Any ideas? I cant seem to find much information on this error

Some details:

  • Its on the Kovan testnet, not a localchain
  • Iā€™ve tried it on two different Moralis server instances

Versions:
ā€œmoralisā€: ā€œ^0.0.181ā€,
ā€œreact-moralisā€: ā€œ^0.3.11ā€,

this is a working example in vanilla js for runContractFunction: [SOLVED] Calling functions on BSC deployed contract

Ah, I was unaware runContractFunction didnā€™t use web3, it could be getting rejected because the user is not logged into the Moralis database.

My app explicitly uses react-moralisā€™ const { web3, enableWeb3, isWeb3Enabled, isWeb3EnableLoading, web3EnableError } = useMoralis() so authenticate() is not used.

Should I return to attempt and get useWeb3ExecuteFunction working again (error TypeError: Cannot read properties of undefined (reading 'call')

or shall I attempt to use Moralis.executeFunction(options)?

Thank you for your help!

it depends on your needs, if you want to all a read only function then it is enough to use runContractFunction, if you want to do a mint for example, then. you will need exeuteFunction or using web3 directly

Thanks for your feedback - I definitely donā€™t need runContractFunction for the use-case then.

Iā€™ve implemented Moralis.executeFunction but iā€™m getting the same error message here as when I was attempting to utilise useWeb3ExecuteFunction()

TypeError: Cannot read properties of undefined (reading 'call')

I donā€™t know where from you get that error, this is the documentation for vanilla js for executeFunction: https://docs.moralis.io/moralis-server/web3/web3#executefunction