ethers.js. Developers can often reuse ethers-based approaches with the right configurations.
If direct on-chain queries are difficult, we’ll also explore how to fall back to peaq.subscan.io, a web-based explorer that allows you to look up balances via an HTTPS GUI.
Prerequisites
- Basic understanding of JavaScript and Node.js.
- You have
ethers.jsinstalled and know how to initialize a provider. - Possess a target wallet address for which you want to check the balance.
- Have access to a running peaq node’s RPC endpoint or a compatible provider.
- Understand how to use peaq.subscan.io as a fallback.
Instructions
1. Set Up Your Environment:
Ensure you havenode and npm installed, then run:
2. Initialize the Provider:
In your JavaScript file (e.g.,checkBalance.js), import ethers and instantiate a provider. Point it to the RPC endpoint of the peaq network you’re connecting to (this might be a testnet or mainnet endpoint—adjust accordingly):
3. Fetch the Wallet Balance:
Use the provider’sgetBalance method, passing in the wallet address. The address should be an Ethereum-compatible format (e.g., 0x…):
4. Fallback to peaq.subscan.io
If the direct query via ethers fails (due to network incompatibilities at the time of querying), you can manually check the balance using the peaq Subscan explorer:- Navigate to: peaq Subscan (mainnet) , agung Subscan (testnet)
- Enter the wallet address into the search bar.
- Press “Enter” or click the search icon.
- View the displayed account information and check the reported balance.
5. Interpreting the Results
Whether you retrieved the balance programmatically viaethers.js or via peaq.subscan.io, you’ll see the current token holdings associated with that address.
Make sure you understand the units (often the smallest unit might be displayed, and you may need to convert them to a more human-readable format).
Summary
Checking wallet balances on the peaq network can be attempted throughethers.js if the network is EVM-compatible and you have the correct provider endpoint.
In the event of issues, the peaq.subscan.io explorer provides a simple GUI fallback. By combining these approaches, developers and users can confidently monitor
and verify the holdings in their peaq wallets.
