(SOLVED) Web3 API - Function does not exist in abi

Hi,

Iā€™m trying to call a function in a smart contract through the Web3 API, but I keep receiving an error code 400 ā€œFunction does not exist in abiā€.

Iā€™m new to this, so I suppose Iā€™m forgetting something.

Could anyone point me in the right direction?

Thanks in advance.

I think that you should write only the function name in function_name field, without the parameters

I removed the parameter from the function_name field and added it to the request body:

"params": {"shareholder":"0x64a..."}

I still get the same error ā€œFunction does not exist in abiā€.

However, the function does exist in the contract:

    function getUnpaidEarnings(address shareholder) public view returns (uint256) {
        if(shares[shareholder].amount == 0){ return 0; }

        uint256 shareholderTotalDividends = getCumulativeDividends(shares[shareholder].amount);
        uint256 shareholderTotalExcluded = shares[shareholder].totalExcluded;

        if(shareholderTotalDividends <= shareholderTotalExcluded){ return 0; }

        return shareholderTotalDividends.sub(shareholderTotalExcluded);
    }

Can you paste the abi only for that function and the topic that you used?

Iā€™m not sure what you mean by ā€œthe topic that I usedā€.

Iā€™ve limited the abi to that specific function only, but it didnā€™t change the result.

{
  "abi": [{"inputs":[{"internalType":"address","name":"shareholder","type":"address"}],"name":"getUnpaidEarnings","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
  "params": {"shareholder": "0x64a..."}
}

a working example:

x = await Moralis.Web3API.native.runContractFunction({
          chain: 'eth',
          address: '0xfcb1315c4273954f74cb16d5b663dbf479eec62e',
          function_name: 'tokenURI',
          abi: [{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}],
            params: { tokenId: 700 }
        })

Thanks a lot for your example! I figured it out now.
I used ā€œtokenURI()ā€ instead of just ā€œtokenURIā€ under function_name.