The following explains how to retrieve wallet balances on the peaq network using 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.js installed 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 have node and npm installed, then run:

npm install ethers

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):

import { ethers } from "ethers";

// Recommended / Example endpoint: replace with your chosen peaq RPC URL
const peaqProvider = new ethers.JsonRpcProvider("https://peaq.api.onfinality.io/public");

3. Fetch the Wallet Balance:

Use the provider’s getBalance method, passing in the wallet address. The address should be an Ethereum-compatible format (e.g., 0x…):

async function getPeaqBalance(address) {
    try {
        const balanceBigInt = await peaqProvider.getBalance(address);
        const balanceEth = ethers.formatEther(balanceBigInt);
        console.log(`Balance of ${address}: ${balanceEth} PEAQ`);
    } catch (error) {
        console.error('Error fetching balance:', error);
        console.log('Falling back to peaq.subscan.io...');
    }
}

// Example usage:
const myAddress = "0xYourPeaqAddress";
getPeaqBalance(myAddress);

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 via ethers.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 through ethers.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.