[SOLVED] Function_name should not be empty when using runContractFunction()

Hi.

I am trying to use runContractFunction() like this.

const options = {
      chain: "0x13881",
      address: "0xD91212683F8F7e3010dAaa9E29031A518453ebd9",
      function_name: "getRound",
      abi:
      {
        inputs: [],
        name: "getRound",
        outputs: [
          {
            internalType: "int256",
            name: "",
            type: "int256"
          }
        ],
        stateMutability: "view",
        type: "function"
      },
      params: {},
    } as const;

    const round = await Moralis.Web3API.native.runContractFunction(options);

But I get the following error

400 (Bad Request)
Uncaught (in promise) Error: {"message":"Cannot read properties of undefined (reading 'inputs'), abi must contain at least 1 elements, Function `undefined` not found in ABI, function_name should not be empty"}

It says function_name is empty, but it is clearly defined. What am I missing?

Try different forms like functionName

In that abi it doesn’t have a name that function?

I tried with functionName but get the same error response back @cryptokid

try to write the abi in this form [ { } ], now it is in this form {}

I tested it here:
https://deep-index.moralis.io/api-docs-2.1/#/Utils/runContractFunction

with this body:

{
  "abi": [{
        "inputs": [],
        "name": "getRound",
        "outputs": [
          {
            "internalType": "int256",
            "name": "",
            "type": "int256"
          }
        ],
        "stateMutability": "view",
        "type": "function"
      }],
  "params": {}
}

and it worked

Weird does not work for me. I wonder if it is related to server. I followed the self hosted setup guide. https://docs.moralis.io/docs/self-hosted-moralis-server

what is the current code that you use?

I use this code for the backend

Followed this tutorial

what is the code that you are using now?

did you make the changes with [ ] ?

Yes I tried with [] as well but same issue

You’re using this in your app?

const options = {
        chain: '0x13881',
        address: '0xD91212683F8F7e3010dAaa9E29031A518453ebd9',
        function_name: 'getRound',
        abi: [
          {
            inputs: [],
            name: 'getRound',
            outputs: [
              {
                internalType: 'int256',
                name: '',
                type: 'int256',
              },
            ],
            stateMutability: 'view',
            type: 'function',
          },
        ],
        params: {},
      } as const;

You will need to also apply a patch for your Parse server, there is a thread here.

Alternatively if you use functionName, it should work without this server patch, but there will be a type error.

2 Likes

We solved it by just adding functionName to the options, no change on the server side.

const options = {
        chain: '0x13881',
        address: '0xD91212683F8F7e3010dAaa9E29031A518453ebd9',
        function_name: 'getRound',
        abi: [
          {
            inputs: [],
            name: 'getRound',
            outputs: [
              {
                internalType: 'int256',
                name: '',
                type: 'int256',
              },
            ],
            stateMutability: 'view',
            type: 'function',
          },
        ],
        params: {},
        functionName: "getRound"
      } as const;

Very confusing, since just renaming “function_name” caused the type error. Thanks for your help, but maybe this should be changed in an upcoming release.

1 Like