[SOLVED] Error 400 when using runContractFunction()

Hi, I am trying to read data from a contract so I use the following

const saleStarted = await Moralis.Web3API.native.runContractFunction(options)

However, it returns me with error 400 according to some information I read on the forum error 400 is returned when options is wrong.
But for options I followed the moralis documentation this is my option object:

  const options = {
    chain: "rinkeby",
    address : params.contractId,
    function_name : "saleStarted",
    abi : ContractABI2
  }

Lastly the error:

Error: {}
    at Function.<anonymous> (MoralisWeb3Api.js:341:1)
    at tryCatch (runtime.js:63:1)
    at Generator.invoke [as _invoke] (runtime.js:294:1)
    at Generator.throw (runtime.js:119:1)
    at asyncGeneratorStep (asyncToGenerator.js:5:1)
    at _throw (asyncToGenerator.js:31:1)

If you try with the example from documentation then it works for you?
https://docs.moralis.io/moralis-dapp/web3-sdk/native#runcontractfunction

You can also look in network tab in browser to see exactly what parameters were sent and what was the response

Hi, the request was:

abi: [{inputs: [{internalType: "string", name: "_eventName", type: "string"},…],…}, {anonymous: false,…},…]
address: "0x7d2400b35d0bA176387cA0A007e84F592562ab4"
chain: "rinkeby"
function_name: "saleStarted"
_ApplicationId: "removedbyMe"
_SessionToken: "r:21688c7548099bcc51dbe379abbd8dd3

and the response:

{"code":141,"error":"{}"}

Well it feels like there was an error with this contract, I cannot find it on etherscan thus the error.
If I use a new contract the function works properly.

1 Like