A Next.js-based blockchain explorer for the Mintlayer network, providing comprehensive insights into blocks, transactions, addresses, pools, and delegations on both mainnet and testnet.
๐ Features
- Block Explorer: Browse blocks, transactions, and addresses
- Pool Management: View staking pools and delegation information
- Token Support: Explore tokens and NFTs on the Mintlayer network
- Responsive Design: Mobile-friendly interface built with Tailwind CSS
๐ Prerequisites
- Node.js: Version 18.x or higher
- npm: Version 8.x or higher (comes with Node.js)
๐ ๏ธ Installation
1. Clone the Repository
git clone https://github.com/mintlayer/explorer.git
cd explorer2. Install Dependencies
3. Environment Configuration
Create a .env.local file in the root directory (or copy from .env):
Configure the following environment variables:
Required Variables
# Network configuration (testnet or mainnet) NETWORK=testnet # Server URL for the application SERVER_URL=http://localhost:3000
Optional Variables
# Override default API URL (optional) NODE_API_URL= # CoinMarketCap API key for price data (optional) CMC_API_KEY=your_cmc_api_key_here # Basic authentication (optional, format: username:password) BASIC_AUTH= # ERC20 data server URL (optional) ER20_DATA_SERVER_URL=https://token.api.mintlayer.org/api
4. Database Setup
The application uses SQLite for caching pool data. The database will be automatically created when you first the pool worker.
5. Populate Pool Data
To display pool information, you need to run the pool data worker:
This script:
- Fetches all pools from the Mintlayer API
- Retrieves delegation information for each pool
- Calculates effective pool balances
- Stores the processed data in the local SQLite database
Note: Run this periodically to keep pool data up-to-date. Consider setting up a cron job for production environments.
๐โโ๏ธ Development
Start Development Server
Open http://localhost:3000 to view the explorer in your browser.
Available Scripts
# Development npm run dev # Start development server npm run build # Build for production npm run start # Start production server # Data Management npm run start:worker # Populate pool data # Code Quality npm run lint # Run ESLint npm run test # Run Jest tests
๐๏ธ Project Structure
explorer/
โโโ src/
โ โโโ app/ # Next.js App Router pages
โ โ โโโ (homepage)/ # Homepage components
โ โ โโโ _components/ # Shared UI components
โ โ โโโ api/ # API routes
โ โ โโโ address/ # Address pages
โ โ โโโ block/ # Block pages
โ โ โโโ pool/ # Pool pages
โ โ โโโ ...
โ โโโ config/ # Configuration files
โ โโโ hooks/ # React hooks
โ โโโ lib/ # Utility libraries
โ โโโ providers/ # React context providers
โ โโโ utils/ # Utility functions
โโโ workers/ # Background workers
โ โโโ pools.js # Pool data fetcher
โโโ public/ # Static assets
โโโ .env # Environment variables template
โโโ data.db # SQLite database (auto-generated)
๐ณ Docker Support
Build Docker Image
docker build -t mintlayer-explorer .Run with Docker
docker run -p 3000:3000 \ -e NETWORK=testnet \ mintlayer-explorer
Docker Compose (Optional)
Create a docker-compose.yml:
version: '3.8' services: explorer: build: . ports: - "3000:3000" environment: - NETWORK=testnet - SERVER_URL=http://localhost:3000 volumes: - ./data.db:/usr/src/app/data.db
๐ง Configuration
Network Configuration
The explorer supports two networks:
- Testnet (default):
NETWORK=testnet - Mainnet:
NETWORK=mainnet
Network configuration affects:
- API endpoints used
- Address format validation
- UI color scheme
- Pool ID prefixes
API Configuration
By default, the application uses official Mintlayer API servers:
- Testnet:
api-server-lovelace.mintlayer.org - Mainnet:
api-server.mintlayer.org
Override with NODE_API_URL environment variable if needed.
๐งช Testing
Run the test suite:
The project uses Jest for testing with TypeScript support.
๐ Production Deployment
1. Build the Application
2. Start Production Server
3. Set Up Pool Data Updates
Set up a cron job to regularly update pool data:
# Update pool data every 10 minutes */10 * * * * cd /path/to/mintlayer-explorer && npm run start:worker
๐ Troubleshooting
Common Issues
-
Pool data not showing
- Run
npm run start:workerto populate the database - Check network connectivity to Mintlayer API servers
- Run
-
Build errors with better-sqlite3
- Ensure you have Python and build tools installed
- On Ubuntu/Debian:
sudo apt-get install python3 build-essential - On macOS: Install Xcode command line tools
-
WASM module issues
- The project includes pre-built WASM binaries
- If issues persist, check the
src/utils/mintlayer-crypto/pkg/directory
-
Environment variables not loading
- Ensure
.env.localexists and contains required variables - Restart the development server after changing environment variables
- Ensure
Performance Optimization
- Pool data is cached in SQLite to reduce API calls
- Consider implementing Redis for production caching
- Use CDN for static assets in production
๐ค Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Commit changes:
git commit -am 'Add new feature' - Push to branch:
git push origin feature/new-feature - Submit a pull request
Code Style
The project uses:
- ESLint for code linting
- Prettier for code formatting
- Husky for git hooks
- lint-staged for pre-commit checks
๐ License
This project is licensed under the terms specified in the LICENSE file.