[SOLVED] runContractFunction returns 400

Hello! I have encountered a problem with the runContractFunction from the Moralis API. When I run the function inside my react application it returns with an error code 400 and Moralis SDK Core Error: [C0006] Request failed, (400): invalid type (argument="type", value="a", code=INVALID_ARGUMENT, version=abi/5.0.7).

The code looks like this

export default function useRetrievePoolLiquidity(lpAddress) {
    const retrieve = async () => {
        await Moralis.start({
            apiKey: process.env.MORALIS_API_KEY,
        })

        const response = await Moralis.EvmApi.utils.runContractFunction({
            address: lpAddress,
            chain: config.chainId,
            abi: tlpAbi,
            functionName: "getPoolLiquidity",
            params: {},
        })

        console.log(response)
    }

    useEffect(() => {
        retrieve()
    }, [])
}

config.chainId, tlpAbi, process.env.MORALIS_API_KEY and Moralis are provided and imported correctly. Any guess to why the function still returns the error?

Moralis 2.0 is backend focused whereas your app is a react-based one whereas Moralis.EvmApi.utils is from moralis2.0 . Instead, you can get runContractFunction from useApiContract here which is a react-hook.

So it is not best practice to use Moralis 2.0 for frontend react applications? Should I be using react-moralis instead?

You can use moralis 2.0 with NextJs. as it’s not supported on the client side. You can use react-moralis instead

Solution: [SOLVED] MoralisProvider with api key for useApiContract hook