Using useMoralisWeb3ApiCall runContractFunction

I am getting a Wep3 API error while trying to get the totalSupply of tokens.

import { useMoralisWeb3Api, useMoralisWeb3ApiCall } from "react-moralis";
import { Moralis } from "moralis";
import { TestContractAbi, TestcontractAddress } from "../data/ContractData";
import { Container, PrimarySection } from "../components/Themes";

const contractAddress = TestcontractAddress;
const contractAbi = JSON.stringify(TestContractAbi);
console.log(contractAbi);
function test() {
  const {
    native: { runContractFunction },
  } = useMoralisWeb3Api();
  const getTotalSupply = useMoralisWeb3ApiCall(runContractFunction, {
    chain: "rinkeby",
    address: contractAddress,
    function_name: "totalSupply",
    abi: {
      inputs: [],
      name: "totalSupply",
      outputs: [
        {
          internalType: "uint256",
          name: "",
          type: "uint256",
        },
      ],
      stateMutability: "view",
      type: "function",
    },
  });

  return (
    <>
      <PrimarySection>
        <Container></Container>
      </PrimarySection>
      <PrimarySection>
        <Container>
          <button onClick={() => getTotalSupply.fetch()}>
            get total supply
          </button>
          <pre>{JSON.stringify(getTotalSupply, null, 2)}</pre>
        </Container>
      </PrimarySection>
    </>
  );
}

export default test;

always provide exact error

image

Sorry I forgot to attach.

thanks which contract address?

0x26475cDF0C530e0296C8862c1933821cbAD2F4be

an example that works with Moralis SDK for another contract:

x = await Moralis.Web3API.native.runContractFunction({
          chain: 'mumbai',
          address: '0xf1B09593d659D3F28DEC21E9C5A60d2FE8B4F940',
          function_name: 'totalPublicSupply',
          abi: [{"inputs":[],"name":"totalPublicSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
          params: {},
        })

the version that works for that specific smart contract:

x = await Moralis.Web3API.native.runContractFunction({
          chain: 'rinkeby',
          address: '0x26475cDF0C530e0296C8862c1933821cbAD2F4be',
          function_name: 'totalSupply',
          abi: [{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
          params: {},
        })
1 Like

chain: 'mumbai'

Types of property β€˜chain’ are incompatible.

Typescript: Type 'string' is not assignable to type ""eth" | "0x1" | "ropsten" | "0x3" | "rinkeby" | "0x4" | "goerli" | "0x5" | "kovan" | "0x2a" | "polygon" | "0x89" | "mumbai" | "0x13881" | "bsc" | "0x38" | "bsc testnet" | "0x61" | ... 6 more ... | undefined"

you get that error from the runContractFunction? also did you have a try whether it’s successful or not, probably just some missing type declaration, although pretty weird coz I can see mumbai there in type chain :thinking: