Error network does not support ENS taking balance

hi everybody…

I am trying to capture the balance of the user connecting to my DAPP with ethers.js

According to its documentation it is done like this:

// Get the balance of an account (by address or ENS name, if supported by network)
balance = await provider.getBalance("ethers.eth")
// { BigNumber: "2337132817842795605" }

I work in BSC testnet. I don’t know very well what the ENS refers to.

I copy the function of my App.js that tries to capture this data

  async function requestAccount() {
    const account = await  window.ethereum.request({ method: 'eth_requestAccounts' });

    const provider = new ethers.providers.Web3Provider(window.ethereum)
    const balance = await provider.getBalance("ethers.eth");

     document.querySelector('#wallet').innerHTML=account.toString();
     document.querySelector('#balance').innerHTML=balance.toString();
  }

I have solved like this…

Sorry for doing this post then.

    const provider = new ethers.providers.Web3Provider(window.ethereum)
    const signer = provider.getSigner(); // user
    const contractUser = await signer.getAddress();
    const contractUserBalance = await provider.getBalance(contractUser);
    const amount = ethers.utils.formatEther(contractUserBalance)


1 Like

If someone knows how to update the data in the front every time the account is changed in the metamask I would appreciate it …
Greetings.