Checking Bitcoin Balances from WIF Private Keys Using Python

This article provides a technical and end-to-end guide for checking Bitcoin balances derived from private keys in WIF (Wallet Import Format) using Python. It covers environment setup, dependency installation, execution flow, network behavior, limitations, and extensibility.
1. Environment Requirements
The following components are required:
- Python 3.8 or newer
- pip (Python package manager)
- Active internet connection
2. Installing Dependencies
The script depends on external libraries for Bitcoin key handling and HTTP communication.
Required packages:
- bit — private key handling, address derivation, and balance queries
- requests — HTTP networking (used internally)
Install using pip:
3. Input File Structure
Create a file named keys.txt in the same directory as the script.
Rules:
- One WIF private key per line
- Empty lines are ignored
- Lines starting with ❌ are skipped
Example:
4. Python Script
The script below reads WIF private keys, derives Bitcoin addresses, and retrieves confirmed on-chain balances:
5. Execution Flow
Runtime process:
1. Load WIF keys from keys.txt
2. Convert each WIF into a private key object
3. Derive the corresponding Bitcoin address
4. Query blockchain data for confirmed balance
5. Print address and balance to stdout
6. Network and Blockchain Context
Technical characteristics:
- Operates on Bitcoin mainnet by default
- Testnet is not enabled without modifying key instantiation
- Balance data reflects confirmed transactions only
- Mempool (unconfirmed) data is excluded
7. Address Types
The derived address format depends on the WIF encoding:
- Compressed WIF → SegWit-compatible or P2PKH address
- Uncompressed WIF → Legacy P2PKH address
The script does not normalize or enforce a specific address type.
8. Data Source Behavior
The bit library retrieves balance data via third-party blockchain service providers.
Implications:
- Subject to rate limits
- Dependent on external API availability
- Accuracy reflects upstream blockchain indexers
9. Performance Characteristics
Processing model:
- Sequential execution
- One balance query per WIF
- Suitable for small to medium datasets
Large key sets may experience latency.
10. Error Handling Model
All exceptions are handled using a single try/except block.
Error sources may include:
- Invalid WIF encoding
- Unsupported key format
- Network or API failures
Script execution continues even if individual keys fail.
11. Output Format
Results are printed directly to the terminal:
No structured export (CSV / JSON) is performed by default.
12. Extension Opportunities
Possible technical extensions:
- Asynchronous or parallel execution
- CSV or JSON output
- Testnet support
- Separation of validation and network errors
- Integration with a self-hosted Bitcoin node
- Inclusion of unconfirmed balance data
13. Summary
This implementation provides a direct and minimal pipeline for converting WIF private keys into Bitcoin addresses and retrieving their confirmed balances. It serves as a solid base for balance validation, monitoring tools, or further blockchain analysis workflows.
