A Node.js application that indexes Ethereum blockchain data into a PostgreSQL database and provides API endpoints to query the indexed data.
- Indexes Ethereum blocks and transactions
- Stores blockchain data in PostgreSQL
- Provides RESTful API endpoints to query indexed data
- Built with Node.js, Express, ethers.js, and PostgreSQL
- Node.js (v14 or higher)
- PostgreSQL (v12 or higher)
- Alchemy API key
-
Clone the repository:
git clone https://github.com/yourusername/ethereum-indexer.git cd ethereum-indexer -
Install dependencies:
npm install
-
Create a
.envfile in the root directory with the following variables:ALCHEMY_API_KEY=your_alchemy_api_key POSTGRES_USER=your_postgres_user POSTGRES_PASSWORD=your_postgres_password POSTGRES_DB=ethereum_indexer POSTGRES_HOST=localhost POSTGRES_PORT=5432 PORT=3000 -
Create the PostgreSQL database:
psql -U postgres CREATE DATABASE ethereum_indexer; \q
npm startFor development with auto-restart:
npm run devGET /health- Check server health and indexing statusGET /blocks/:number- Get block data by block numberGET /transactions/:hash- Get transaction data by transaction hash
ethereum-indexer/
├── src/
│ ├── index.js # Main application entry point
│ ├── db.js # Database connection
│ ├── schema.js # Database schema
│ └── indexer.js # Blockchain indexing logic
├── .env # Environment variables
├── package.json # Project dependencies
└── README.md # Project documentation
- The application connects to the Ethereum network using Alchemy's API
- It fetches blocks and transactions from the blockchain
- The data is stored in PostgreSQL tables
- The Express server provides API endpoints to query the indexed data
number- Block number (primary key)hash- Block hashparent_hash- Parent block hashtimestamp- Block timestampminer- Miner addressgas_used- Gas used in the blockgas_limit- Gas limit of the blockbase_fee_per_gas- Base fee per gas (EIP-1559)indexed_at- Timestamp when the block was indexed
hash- Transaction hash (primary key)block_number- Block number (foreign key)from_address- Sender addressto_address- Recipient addressvalue- Transaction value in weigas_used- Gas used by the transactiongas_price- Gas price in weinonce- Transaction noncetransaction_index- Index of the transaction in the blockstatus- Transaction status (success/failure)indexed_at- Timestamp when the transaction was indexed
- Index contract events (logs)
- Track token transfers (ERC-20, ERC-721)
- Monitor account balances
- Add support for chain reorganizations
- Implement more advanced querying capabilities


