A high-performance REST API built with Go and Gin framework for exploring Ethereum blockchain data. This API provides endpoints to fetch transaction details, block information, wallet balances, and current network statistics.
- Block Information: Fetch detailed block data by number.
- Transaction Details: Get comprehensive transaction information by hash.
- Wallet Balances: Check ETH balance for any address.
- Latest Block: Get the most recent block data.
- Gas Price: Get the current network gas price
- Health Check: Endpoint to check the status of the API.
eth-explorer-api/
├── cmd/
│ └── main.go # Application entry point
├── internal/
│ ├── config/
│ │ └── config.go # Configuration management
│ ├── handlers/
│ │ └── eth.go # HTTP request handlers
│ ├── services/
│ │ └── eth_service.go # Ethereum blockchain service
│ └── models/
│ └── models.go # Data models and structures
├── .env # Environment variables
├── go.mod # Go module dependencies
└── README.md # This file
### Prerequisites
- Go 1.21 or higher
- An Ethereum node URL (e.g., from Infura, Alchemy, or a local node)
### 1. Clone the Repository
```bash
git clone <repository-url>
cd eth-explorer-api
go mod tidyCreate a .env file in the root directory with the following content:
# Server configuration
PORT=8080
# Ethereum Node URL
ETH_NODE_URL=https://mainnet.infura.io/v3/YOUR_PROJECT_ID
Replace YOUR_PROJECT_ID with your actual Ethereum node project ID.
go run cmd/main.goThe server will start on http://localhost:8080.
The base URL for all endpoints is http://localhost:8080/api/v1.
GET /eth/block/:number
:number: The block number (e.g.,18500000) or"latest".
GET /eth/transaction/:hash
:hash: The transaction hash.
GET /eth/balance/:address
:address: The Ethereum wallet address.
GET /eth/history/:address
:address: The Ethereum wallet address.
GET /eth/token-balance/:address/:tokenAddress
:address: The Ethereum wallet address.:tokenAddress: The ERC-20 token contract address.
GET /eth/token-transfers/:address
:address: The Ethereum wallet address.
GET /eth/contract-abi/:address
:address: The smart contract address.
GET /eth/contract-source/:address
:address: The smart contract address.
GET /eth/event-logs/:address
:address: The smart contract address.topics(query param): A comma-separated list of event topics to filter by.
GET /eth/latest-block
GET /eth/gas-price
GET /health