Method Signature
align.blockchain.wallets.getBalance(
address: string,
network: Network
): Promise<string>
Parameters
The wallet address to check
Network: ethereum, polygon, base, arbitrum, optimism
Returns
Returns the balance as a formatted string (e.g., "1.5" for 1.5 ETH/MATIC).
Examples
import Align from "@tolbel/align";
const align = new Align({
apiKey: process.env.ALIGN_API_KEY!,
environment: "sandbox",
});
const balance = await align.blockchain.wallets.getBalance(
"0x742d35Cc6634C0532925a3b844Bc9e7595f0aB42",
"polygon"
);
console.log(`Balance: ${balance} MATIC`);
// Balance: 125.5 MATIC
const balance = await align.blockchain.wallets.getBalance(
"0x742d35Cc6634C0532925a3b844Bc9e7595f0aB42",
"polygon"
);
console.log("Balance:", balance, "MATIC");
Check Multiple Networks
const address = "0x742d35Cc6634C0532925a3b844Bc9e7595f0aB42";
type NetworkBalance = { network: string; balance: string };
const networks = ["ethereum", "polygon", "base", "arbitrum"] as const;
for (const network of networks) {
const balance = await align.blockchain.wallets.getBalance(address, network);
console.log(`${network}: ${balance}`);
}
Check Before Transaction
const wallet = await align.blockchain.wallets.create();
const balance = await align.blockchain.wallets.getBalance(
wallet.address,
"polygon"
);
if (parseFloat(balance) < 0.01) {
console.error("Insufficient funds for gas fees");
} else {
// Proceed with transaction
await align.blockchain.transactions.sendToken(
wallet,
"usdc",
recipient,
"100",
"polygon"
);
}