Invalid Function getNativeBalance when trying to use the newly added Web3API feature

Greetings, I’m working on a side a project involving Moralis and React-Moralis i’m using latest versions
here’s my package.json details
“moralis”: “^0.0.37”,
“react-moralis”: “^0.2.1”
I’m using yarn for package management and I made sure that i have upgraded properly from 0.2.0 to 0.2.1 same goes for the moralis package.
Just to be sure i even removed them and re-added them using the appropriate yarn commands still didn’t resolve my issue.
Here’s an example component which I created to test the new functionality which was nicely provided, much appreceated.
Both getNativeBalanceQuery.fetch() and Moralis.Web3API.account.getNativeBalance() fail with the same error
{“code”:141,“error”:“Invalid function: “getNativeBalance””}

Any help will be highly appreciated, thanks in advance.

import React from 'react'
import { useMoralis,useMoralisWeb3Api, useMoralisWeb3ApiCall } from "react-moralis"
const Charts = () => {
const { native: { getBlock }, account: { getNativeBalance } } = useMoralisWeb3Api();

const getNativeBalanceQuery = useMoralisWeb3ApiCall(getNativeBalance, {
address:"0xaA44AAEf36D866BA4fe9Def5d11426B9A87115E1",
});

const {authenticate, logout, isAuthenticated,authError, hasAuthError,user, enableWeb3,isAuthenticating, isWeb3Enabled, Moralis, web3} = useMoralis()

return (

{isAuthenticated && isWeb3Enabled ?
<>
<button onClick={ async ()=>{
console.log(Moralis.Web3API);
//Neither this worked
console.log(await Moralis.Web3API.account.getNativeBalance({chain:"0x61",address:"0xaA44AAEf36D866BA4fe9Def5d11426B9A87115E1"}))
//Or this worked both result in same error.
getNativeBalanceQuery.fetch()
}}>Test func
</>
: null}

)
}
export default Charts

Hi,
This works fine for me:

await Moralis.Web3API.account.getNativeBalance({chain:"0x61",address:"0xaA44AAEf36D866BA4fe9Def5d11426B9A87115E1"})
=>
{balance: "2343894087996668536"}

You may also have to upgrade the Moralis server in case that doesn’t have the latest version (0.0.251)

1 Like

Moralis server wasn’t updated. Issue closed thanks!

2 Likes