The Etherscan Scraper is a CLI tool built with Python that fetches Ethereum blockchain transactions from Etherscan.io. It allows users to specify a block range, filter transactions by method or amount, and store results in a JSON file or a PostgreSQL database.
- Query Ethereum transactions from Etherscan API
- Specify block range (max 100 blocks)
- Filter transactions by method and amount (0 or non-0 ETH)
- Save data to JSON or PostgreSQL
- Uses
.envfor API keys and database configuration
Ensure you have the following installed:
- Python 3.9+
- pip (Python package manager)
- PostgreSQL (optional, for database storage)
- Docker & Docker Compose (optional, for PostgreSQL setup)
- Clone the repository:
git clone <repository-url> cd etherscan_scraper
- Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # MacOS/Linux venv\Scripts\activate # Windows
- Install dependencies:
pip install -r requirements.txt
Create a .env file in the project root and add the following:
ETHERSCAN_API_KEY=your_api_key_here
SAVE_TO=json # or postgres
JSON_PATH=./transactions.json
# PostgreSQL Configuration (if using database storage)
DB_HOST=localhost
DB_PORT=5432
DB_NAME=etherscan
DB_USER=postgres
DB_PASS=postgresRun the following command to fetch transactions within a specified block range:
python etherscan_scraper.py --start 21442021 --end 21442120 --method transfer --amount 0--start: Starting block number (required)--end: Ending block number (required, max range of 100 blocks)--method: Filter by transaction method (optional)--amount:0(only 0 ETH) or1(non-0 ETH) (optional)
- If
SAVE_TO=json, transactions will be saved intransactions.json. - If
SAVE_TO=postgres, transactions will be inserted into a PostgreSQL database.
- Start PostgreSQL using Docker:
docker-compose up -d
- Connect to the database:
psql -h localhost -U postgres -d etherscan
[
{
"hash": "0x123abc...",
"status": "Success",
"block": 21442021,
"timestamp": 1739553046,
"from": "0xabc...",
"to": "0xdef...",
"value": 1.5,
"transaction_fee": 0.00042,
"gasUsed": 21000,
"gasPrice": 20000000000,
"method": "0x12345678",
"sponsored": "N/A"
}
]- Fork the repository
- Create a feature branch (
git checkout -b feature-name) - Commit changes (
git commit -m "Add new feature") - Push to GitHub (
git push origin feature-name) - Open a pull request
This project is licensed under the MIT License.
For questions or suggestions, please open an issue or contact the repository owner.