I would like to use this code in order to get the account balance and display it on my react app.
state = {
croBalance: "",
};
async componentDidMount() {
const balance = await web3.eth.getBalance(
"0xu28yjy9chxmhiruhgiwgm93h984hmxhumzmr"
);
const etherBalance = await web3.utils.fromWei(balance, "ether");
const finalBalance = etherBalance.substring(0, 6);
// console.log(balance);
this.setState({ croBalance: finalBalance });
}
here is my webb3.js file:
import Web3 from "web3";
window.ethereum.request({ method: "eth_requestAccounts" });
const web3 = new Web3(window.ethereum);
export default web3;
this code hangs when metamask is not on browser like mobile. I would love to be able to query this address without users needing to confirm metamask account.