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!