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