> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spire.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Chain Management

> Monitor and maintain your Pylon appchain

export const DockerComposeStyle = () => {
  useEffect(() => {
    const styleId = 'docker-compose-snippet-styles';
    if (!document.getElementById(styleId)) {
      const style = document.createElement('style');
      style.id = styleId;
      style.textContent = `
        [data-docker-compose-snippet] pre {
          max-height: 18rem !important;
          overflow-y: auto !important;
        }
      `;
      document.head.appendChild(style);
    }
    const updateAttributes = () => {
      const allCodeBlocks = Array.from(document.querySelectorAll('code'));
      const dockerComposeBlock = allCodeBlocks.find(code => {
        const text = code.textContent || '';
        return text.includes('version: \'3.8\'') && text.includes('blockscout-backend') && text.includes('blockscout-frontend');
      });
      if (dockerComposeBlock) {
        const preElement = dockerComposeBlock.closest('pre');
        if (preElement) {
          preElement.setAttribute('data-docker-compose-snippet', 'true');
          const container = preElement.parentElement;
          if (container) {
            container.setAttribute('data-docker-compose-snippet', 'true');
          }
        }
      }
    };
    updateAttributes();
    const timeoutId1 = setTimeout(updateAttributes, 100);
    const timeoutId2 = setTimeout(updateAttributes, 500);
    const observer = new MutationObserver(() => {
      updateAttributes();
    });
    observer.observe(document.body, {
      childList: true,
      subtree: true
    });
    return () => {
      clearTimeout(timeoutId1);
      clearTimeout(timeoutId2);
      observer.disconnect();
    };
  }, []);
  return null;
};

<DockerComposeStyle />

## Overview

Chain management covers monitoring and exploring your Pylon appchain through its RPC endpoint. Since Pylon manages the infrastructure, this guide focuses on setting up a block explorer and basic monitoring tasks you can perform using standard Ethereum RPC methods.

For infrastructure issues (block production problems, cross-chain failures, etc.), contact [Pylon support](https://www.spire.dev/contact). This guide covers application-level monitoring and exploration.

## Block Explorer Setup

[BlockScout](https://blockscout.com/) is an open-source blockchain explorer that provides detailed transaction views, contract verification, and chain analytics. It enables exploring and monitoring appchain transactions through a web interface.

### Quick Start with Docker Compose

BlockScout consists of a backend API and a frontend web application. Before creating the docker-compose file, generate a secret key:

```bash theme={null}
openssl rand -hex 64
```

Save this value to use in the `SECRET_KEY_BASE` environment variable. Then create a `docker-compose.yml` file:

```yaml theme={null}
version: '3.8'

services:
  blockscout-backend:
    image: blockscout/blockscout:latest
    command: sh -c "/app/bin/blockscout eval \"Elixir.Explorer.ReleaseTasks.create_and_migrate()\" && /app/bin/blockscout start"
    ports:
      - "4000:4000"
    environment:
      - ETHEREUM_JSONRPC_HTTP_URL=https://pylon.{settlement-layer}.spire.dev/v1/chain/{chain-id}/rpc
      - ETHEREUM_JSONRPC_WS_URL=wss://pylon.{settlement-layer}.spire.dev/v1/chain/{chain-id}/ws
      - DATABASE_URL=postgresql://postgres:postgres@postgres:5432/blockscout
      - SECRET_KEY_BASE=GENERATE_A_SECRET_KEY_HERE
      - ECTO_USE_SSL=false
      - COIN=ETH
      - NETWORK=Your Appchain Name
      - SUBNETWORK=Your Appchain Name
      - SHOW_MAINTENANCE_ALERT=false
      - DISABLE_EXCHANGE_RATES=true
      - INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=true
      - INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER=true
      - INDEXER_DISABLE_BLOCK_REWARD_FETCHER=true
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    volumes:
      - ./blockscout-data:/var/app/priv/static/images

  blockscout-frontend:
    image: ghcr.io/blockscout/frontend:latest
    platform: linux/amd64
    ports:
      - "8080:3000"
    environment:
      - NEXT_PUBLIC_API_PROTOCOL=http
      - NEXT_PUBLIC_API_HOST=localhost
      - NEXT_PUBLIC_API_PORT=4000
      - NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=ws
      - NEXT_PUBLIC_APP_HOST=http://localhost:8080
      - NEXT_PUBLIC_NETWORK_NAME=Your Appchain Name
      - NEXT_PUBLIC_NETWORK_ID=YOUR_CHAIN_ID
    depends_on:
      - blockscout-backend

  postgres:
    image: postgres:15
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=blockscout
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    volumes:
      - redis-data:/var/lib/redis/data

volumes:
  postgres-data:
  redis-data:
```

**Important Configuration Notes:**

* **RPC URL**: Set `ETHEREUM_JSONRPC_HTTP_URL` to your Pylon RPC endpoint (e.g., `https://pylon.{settlement-layer}.spire.dev/v1/chain/{chain-id}/rpc`)
* **Chain Name**: Update `NETWORK`, `SUBNETWORK`, and `NEXT_PUBLIC_NETWORK_NAME` with your appchain name
* **Chain ID**: Set `NEXT_PUBLIC_NETWORK_ID` to your appchain's Chain ID (found in your Chain Setup details)
* **App Host**: If accessing remotely, update `NEXT_PUBLIC_APP_HOST` to your server's address (e.g., `http://your-domain.com:8080`)
* **Secret Key**: Replace `GENERATE_A_SECRET_KEY_HERE` with the secret key generated above

### Running BlockScout

```bash theme={null}
docker-compose up -d
```

Access BlockScout at `http://localhost:8080`. The frontend connects to the backend API at `http://localhost:4000`. The first sync may take several minutes depending on chain size.

**Note:** BlockScout indexes from the latest block backward, so new transactions appear immediately even while historical blocks are still syncing. The indexing progress banner shows historical sync status, but the latest blocks shown are always current.

For production deployments, see the [BlockScout documentation](https://docs.blockscout.com/) for detailed setup instructions including HTTPS configuration, database backups, and monitoring.

## Basic Monitoring

Use standard Ethereum RPC methods to monitor your appchain's health and activity. The Pylon RPC endpoint supports all standard Ethereum JSON-RPC methods.

### Check Block Production

Verify blocks are being produced:

```bash theme={null}
cast block-number --rpc-url YOUR_RPC_URL
```

### Inspect Transactions

View transaction details:

```bash theme={null}
cast tx TX_HASH --rpc-url YOUR_RPC_URL
```

### Query Contract Events

Query event logs from contracts:

```bash theme={null}
cast logs --from-block 0 --to-block latest \
    --address CONTRACT_ADDRESS \
    --rpc-url YOUR_RPC_URL
```

### View Transaction Receipts

Get transaction receipts to see logs and events:

```bash theme={null}
cast receipt TX_HASH --rpc-url YOUR_RPC_URL
```

For infrastructure issues (blocks not producing, cross-chain failures, etc.), contact [Pylon support](https://www.spire.dev/contact).

## Next Steps

* **[Chain Setup →](/pylon/chain-setup)** - Configure the appchain properly
* **[Build Onchain →](/pylon/build-onchain)** - Deploy and test applications
* **[Connect Users →](/pylon/connect-users)** - Connect wallets for testing
* **[Architecture →](/pylon/architecture)** - Understand the underlying system
