Does anyone know why this code is giving me trouble? It was working earlier now the page won’t even load for 2 seconds without getting above error
Thanks guys
import React, {useState, useEffect} from 'react'
import './Send.css'
import {Button} from 'react-bootstrap';
import { useMoralisWeb3Api } from "react-moralis";
const Send = () => {
const Web3Api = useMoralisWeb3Api();
const [nativeNetwork, setNativeNetwork] = useState();
const [nativeBalance, setNativeBalance] = useState();
const fetchNetwork = () => {
if (window.ethereum.chainId === "0x539") {
setNativeNetwork('Ganache');
} else if (window.ethereum.chainId === "0x1") {
setNativeNetwork('Ethereum')
} else if (window.ethereum.chainId === "0x38") {
setNativeNetwork('Binance')
} else if (window.ethereum.chainId === "0x89") {
setNativeNetwork('Polygon')
} else if (window.ethereum.chainId === "0xa86a") {
setNativeNetwork('Avalanche')
} else if (window.ethereum.chainId === "0xa4b1") {
setNativeNetwork('Arbitrum(L2)')
} else {
setNativeNetwork('Not Supported')
}
};
useEffect(() => {
const fetchBalance = async () => {
let result = await Web3Api.account.getNativeBalance({ address: window.ethereum._state.accounts[0]})
result = result.balance;
if (window.ethereum._state.accounts > [""]) {
setNativeBalance(result);
} else {
setNativeBalance('Disconnected')
}};
fetchNetwork()
fetchBalance()
}, [Web3Api.account])
return(...)
}
export default Send
also when I change the following line:
const Web3Api = useMoralisWeb3Api();
To:
const { Web3Api } = useMoralisWeb3Api();
the new error I get is:
TypeError: Cannot read properties of undefined (reading 'account')
My metamask is unlocked and connected…