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


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.