Getting a metamascus balance in different networks with web3Modal
As a Metamask user, you are probably familiar with the convenience that you can manage your wallet in several blockchain networks. However, navigation of different networks may be stunning, especially when it comes to displaying balances. In this article, we will examine how to use web3Modal to view metamask balance on different networks including Binance Smart Chain (BSC), Ethereum (ETH) and Croakos.
What is metamask?
Metamask is a popular web extension that allows users to manage their cryptomen wallets in several blockchain networks. With metamascus, you can store, send, receive and manage your assets on the road, all within one comfortable interface.
Web3Modal: Complex Library for Web3 integration
Web3modal is an excellent API Web3 library into your web applications. It provides a simple and intuitive API to receive applications for various blockchain networks including BSC, ETH, Croakos and others.
View balance on different networks with web3Modal
To view the balance of your Metamask account in different networks, you must use the Web3Modal ‘Getbalance method. Here are some examples of how to achieve this:
![Metamask: How to get balance on metamask all network [bsc , eth, cro, etc] using web3modal](https://kdrcreole.ca/wp-content/uploads/2025/02/774383f8.png)
Showing Binance Smart Chain (BSC) Balance
`Javascript
Import {ethers} from ‘web3modal’;
Const Web3modal = AWAIT ETHERS.GETPROVIDER (‘
Const Metamaskinstance = New Web3Modal.web3modal ({
Provider: Web3Modal,
});
Async function Getbalance () {)
try {
Const Balance = (expect metamaskinstance.getbalance ()). Tonumber ();
Return BCS Bilant: $ {bilant};
} Catch (Error) {
Console.error (Error);
}
}
Getbalance (). then ((result) => console.log (result));
`
In this example, we use an instance of Metamask, which is provided by Web3modal to obtain the balance of your Binance Smart Chain account. The Getbalance method returns an object with a balance in decimal format.
Showing the Ethereum (ETH) balance
`Javascript
Import {ethers} from ‘web3modal’;
Const Web3modal = AWAIT ETHERS.GETPROVIDER (‘
Const Metamaskinstance = New Web3Modal.web3modal ({
Provider: Web3Modal,
});
Async function Getbalance () {)
try {
Const Balance = (expect metamaskinstance.getbalance ()). Tonumber ();
Return Eth Bilant: $ {bilant};
} Catch (Error) {
Console.error (Error);
}
}
Getbalance (). then ((result) => console.log (result));
`
In this example, we use the same web3Modal instance to obtain your Ethereum account balance on the main network.
Showing Croakos balance
`Javascript
Import {ethers} from ‘web3modal’;
Const Web3modal = AWAIT ETHERS.GETPROVIDER (‘
Const Metamaskinstance = New Web3Modal.web3modal ({
Provider: Web3Modal,
});
Async function Getbalance () {)
try {
Const Balance = (expect metamaskinstance.getbalance ()). Tonumber ();
Return Croakos Bilant: $ {bilant};
} Catch (Error) {
Console.error (Error);
}
}
Getbalance (). then ((result) => console.log (result));
`
In this example, we use the same web3Modal instance to obtain the balance of your Croakos account in the Riskbit.io network.
tips and tricks
- Be sure to replace
your_project_idwith your actual infura project ID.
- You can also use
web3modal.getbalance ()instead ofGetbalance ()To view the balance in another format (eg as a chain or field).
- If you are using the Web3Modal’s
Connect 'method, be sure to call' Deconnect ()when you end up with an instance of metamask.