runContractFunction can't get any data from smart contract ABI [NextJS]

Hello, could you help me? I’ve spent so many days trying to get data from smart contract, I’ve read so many different topics, used different functions and still nothing…

import { useMoralis, useApiContract, useWeb3Contract, useMoralisQuery, useMoralisWeb3Api, useMoralisWeb3ApiCall, useWeb3ExecuteFunction } from 'react-moralis';

const { isInitialized } = useMoralis(); 

const {
      runContractFunction,
      data,
    } = useApiContract({
      address: contract,
      function_name: "rewards",
      abi: {
        "constant": true,
        "inputs": [
            {
                "internalType": "address",
                "name": "",
                "type": "address"
            }
        ],
        "name": "rewards",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    params: { address: useraddr, },
    });

      useEffect(() => {
        if(isInitialized) runContractFunction();
      }, [isInitialized])

      console.log(data);

Output: null

I’ve tried to give input/output names inside ABI, different params etc, runContractFunction always returning null data

With different functions like executeFunction etc. I’ve always had some troubles like Moralis is not authenticated, use Moralis.Start() or Moralis.authenticate
(I think I’ve fixed that…)

or

web3 is not enabled even if I’ve tried different approaches, isWeb3Enabled was showing that it’s true, when I put Moralis.web3enable or smth like that inside function it was showing that web3 was already started, but isn’t fully executed, then isWeb3Loading etc… nothing was working…

Also for runContractFunction tried ContractAddress except address and function_name / FunctionName etc, maybe something with params? Should I give names for address and output uint256 inside ABI?

For now any ideas with read-only data? What am I doing wrong? Something with ABI or what? Help, please. Thanks!

Also after running Moralis.start() I get an error:

error - unhandledRejection: ReferenceError: localStorage is not defined

I’ve tried to fix that with require(‘Moralis/node’) etc. but without success, but I guess it doesn’t matter to runContractFunction, I’ve tried to get data on a pure React test project and still can’t get any data - null

The name here should match with the param passed. So you can make it "name": "_address", and make your param too

_address: useraddr where useraddr looks to be an address from your state

1 Like

Still null, output name is also required?

Name for output is not required. You can also test runContractFunction equivalent directly in web3api tab in admin interface

1 Like

I’ve tried different ABI functions in dashboard and it was working, got some data there, but couldn’t get it here… With different functions I was using wrong params previously in Next App I guess

Here, you need a parameter with that name

1 Like

Is there a limit for tables in dashboard? First 2 synced contract events were working and now new tables doesn’t appear

Like that?

const {
      runContractFunction,
      data,
      error,
    } = useApiContract({
      address: contract,
      functionName: "rewards",
      abi: {
        "constant": true,
        "inputs": [
            {
                "internalType": "address",
                "name": "_address",
                "type": "address"
            }
        ],
        "name": "rewards",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    params: { _address: useraddr },
    });

still null

Make this

This way to be sure if you got something back

if (isInitialized)
  runContractFunction({
    onSuccess: (res) => console.log(res),
    onError: (err) => console.log(err),
  });

1 Like

There is a limit, but you probably didn’t hit it.
You can post the server url in a different forum thread.

1 Like

image

It’s about async await function? I mean all other things like authentication, logout, getERC20Balances etc. I got asynchronous functions, but just trying to get that data and then edit it to async

I don’t understand what you mean here

1 Like

Look in network tab to see the exact error.
The function failed

1 Like

This?

There, look in payload. You could also look in server logs.

1 Like

Can you try it in web3api tab in admin interface?

1 Like

I’ve tried, but new tables doesn’t appear in dashboard (after successfull sync)

nah, ok my Moralis Admin panel, but which web3 Api should I use to get some contract data? or this rewards for my wallet

No, I mean in admin.moralis.io.

What is the connection with tables?