Offical Documentation for Web3 calls is incorrect


Could anyone advise on how to make a basic web3 call with moralis react? I am using runContractFunction and it appears that the documentation is incorrect. In the example cited here:

If I click on the React tab and have my working app running, it appears that the function is triggered by using useMoralisWeb3ApiCall – however this is not exported or imported anywhere

Also I am getting lots of typescript errors where it is complaining that for the chain parameter in the options (I specified “eth” as in the example): I am getting

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

Has anybody here gotten these examples to work?

are you using latest version of Moralis SDK?
probably it was not tested with typescript

Hmm, yeah i was curious how ‘production ready’ Moralis is. Looking at QuickNode now, seems a lot better in terms of having examples that actually work

I mean all the examples are in Typescript, even requires a typescript template when you use create-react-app but I guess actually writing docs that work is maybe too big of a task for such a small team at Moralis

if all you need is nodes, you can use quick node.

the team in working on a new release for the SDK that will also be written directly in typescript:

Hey, there is an easy fix for the type issue. You can have a custom type like so

    type ChainType = 'eth'

    const options = {
        chain: 'eth' as ChainType,
        ....the rest of your options

It was solved before here

1 Like

cool i may come back to this at some point. so the new SDK will be all typescript, they require you to use a typescript template when you make a new react app but then the examples are not supposed to work in typescript? feels like they are trying to create a lot of unnecessary issues for users to me…

The team is trying to bring the best as fast as they can, you are not required to use typescript at all but yeah if you do you might have to fix some types yourself

i see. yeah i was trying to use the react-moralis stuff in a non-typescript app but this does not work. looks like they are growing their team - maybe in a few months we can see some working examples!

It should work in a non-typescript project as well. Make sure you have configured your react project right

No it shouldn’t. It’s just the SDK itself which will be in TypeScript, just like other libraries where you can still use a JS project with.