Skip to content

Explorer providing an interface for searching, viewing, and analyzing transactions, blocks, and addresses on the Mintlayer blockchain

License

Notifications You must be signed in to change notification settings

mintlayer/explorer

Repository files navigation

Mintlayer Explorer

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 explorer

2. Install Dependencies

npm install

3. Environment Configuration

Create a .env.local file in the root directory (or copy from .env):

cp .env .env.local

Configure the following environment variables:

Required Variables

# Network configuration (testnet or mainnet)
NETWORK=testnet
NEXT_PUBLIC_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:

npm run start: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

npm run dev

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 \
  -e NEXT_PUBLIC_NETWORK=testnet \
  mintlayer-explorer

Docker Compose (Optional)

Create a docker-compose.yml:

version: '3.8'
services:
  explorer:
    build: .
    ports:
      - "3000:3000"
    environment:
      - NETWORK=testnet
      - NEXT_PUBLIC_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:

npm test

The project uses Jest for testing with TypeScript support.

πŸš€ Production Deployment

1. Build the Application

npm run build

2. Start Production Server

npm start

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

  1. Pool data not showing

    • Run npm run start:worker to populate the database
    • Check network connectivity to Mintlayer API servers
  2. 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
  3. WASM module issues

    • The project includes pre-built WASM binaries
    • If issues persist, check the src/utils/mintlayer-crypto/pkg/ directory
  4. Environment variables not loading

    • Ensure .env.local exists and contains required variables
    • Restart the development server after changing environment variables

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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Commit changes: git commit -am 'Add new feature'
  4. Push to branch: git push origin feature/new-feature
  5. 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.

πŸ”— Links

About

Explorer providing an interface for searching, viewing, and analyzing transactions, blocks, and addresses on the Mintlayer blockchain

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •