8000 GitHub - bensig/bitcoin-stack: A plug-and-play Bitcoin infrastructure stack. Runs a full Bitcoin Core node with mining, Esplora explorer, and Mempool.space—all in one Docker Compose setup.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A plug-and-play Bitcoin infrastructure stack. Runs a full Bitcoin Core node with mining, Esplora explorer, and Mempool.space—all in one Docker Compose setup.

Notifications You must be signed in to change notification settings

bensig/bitcoin-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Bitcoin Learning Environment

This repository provides a local development environment for learning about Bitcoin through hands-on experimentation. By running a local Bitcoin signet network and Mempool explorer, you can interact with Bitcoin's functionality in a controlled environment without using real funds.

Overview

This project consists of:

  1. Bitcoin Signet - A sandboxed Bitcoin test network where blocks can be mined locally
  2. Esplora Explorer - A web interface for visualizing transactions and blocks
  3. Mempool Dashboard - A comprehensive visualization of Bitcoin's mempool, transactions, and blocks

By connecting various Bitcoin applications to this local environment, you can learn about:

  • Bitcoin transactions and the UTXO model
  • Block mining and confirmation
  • Transaction fees and mempool dynamics
  • Bitcoin scripting and smart contracts
  • Wallet integration and development

Getting Started

Prerequisites

  • Docker and Docker Compose
  • Git

Setup

There are two ways to set up the environment:

Option 1: Using the root-level docker-compose.yml (Recommended)

This single docker-compose file manages both Bitcoin Signet and Esplora services with proper networking:

  1. Clone this repository:

    git clone <repository-url>
    cd <repository-directory>
  2. Start all services with one command:

    docker-compose up -d

    This will:

    • Create a Bitcoin Signet miner node
    • Create a Bitcoin Signet full node (optional, connects to the miner)
    • Start the Esplora block explorer connected to the Bitcoin Signet miner
    • Start the Mempool Dashboard with database and API components
    • Set up proper networking between all services
    • Map all required ports to the host
  3. Access the explorers:

    Important: On first start, it may take some time (1-2 minutes) for all services to initialize and connect to each other. Esplora needs to index the blockchain and Mempool API needs to sync with both Bitcoin and Esplora.

    To access from a remote host, replace localhost with your server's public IP address:

    • Esplora: http://YOUR_SERVER_IP:3001
    • Mempool UI: http://YOUR_SERVER_IP:3002

    Make sure these ports are open in your firewall if accessing remotely:

    sudo ufw allow 3001/tcp
    sudo ufw allow 3002/tcp

Working with the Docker Environment

Once your services are running, you can interact with them:

Checking Service Status
docker-compose ps
Viewing Logs
# View logs for all services
docker-compose logs

# View logs for a specific service
docker-compose logs bitcoin-miner
docker-compose logs esplora

# Follow logs in real-time
docker-compose logs -f
Mining Blocks Manually

You can trigger block mining on the Bitcoin signet miner node:

docker exec bitcoin-miner bitcoin-cli -rpcuser=bitcoin -rpcpassword=bitcoin -rpcport=38332 getblockchaininfo

The mining process runs automatically in the background in signet mode. The miner will create blocks approximately every 30 seconds (as configured by BLOCKPRODUCTIONDELAY). You can watch new blocks appear in both Esplora and Mempool explorers.

If mining isn't progressing, check the miner process:

docker exec bitcoin-miner ps aux | grep mine

You should see the Python miner script running.

Interacting with Bitcoin Signet via RPC

You can use RPC commands to interact with the Bitcoin signet node. Here are some examples:

Get blockchain information:

curl --user bitcoin:bitcoin --data-binary '{"jsonrpc":"1.0","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:38332

Get a new address:

curl --user bitcoin:bitcoin --data-binary '{"jsonrpc":"1.0","method":"getnewaddress","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:38332

Send coins to an address (replace

and ):

curl --user bitcoin:bitcoin --data-binary '{"jsonrpc":"1.0","method":"sendtoaddress","params":["<address>", <amount>]}' -H 'content-type:text/plain;' http://127.0.0.1:38332

List unspent transaction outputs:

curl --user bitcoin:bitcoin --data-binary '{"jsonrpc":"1.0","method":"listunspent","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:38332
Interacting with Mempool API

The Mempool API provides rich data about blocks, transactions, and the mempool state. Here are some examples:

Get recommended fees:

curl http://localhost:3002/api/v1/fees/recommended

Get mempool statistics:

curl http://localhost:3002/api/mempool

Get information about a block by height:

curl http://localhost:3002/api/block/<height>

Get information about a transaction:

curl http://localhost:3002/api/tx/<txid>

Full API documentation can be found at the Mempool GitHub repository.

Stopping Services
docker-compose down
Resetting the Environment

To completely reset the environment (this will delete all blockchain data):

docker-compose down -v
docker-compose up -d

Option 2: Setting up components separately

  1. Clone this repository:

    git clone <repository-url>
    cd <repository-directory>
  2. Start the Bitcoin signet node:

    cd bitcoin_signet
    docker-compose up -d
  3. Start the Mempool explorer:

    cd ../esplora/contrib
    
    # Before running, update the docker-compose.yml to use signet instead of regtest
    # Change the command line from:
    # - '/srv/explorer/run.sh bitcoin-regtest explorer nonverbose'
    # to:
    # - '/srv/explorer/run.sh bitcoin-signet explorer nonverbose'
    
    docker-compose up -d

    Alternatively, run directly with Bitcoin signet configuration:

    docker run -p 50001:50001 -p 8084:80 \
               --volume $PWD/data_bitcoin_signet:/data \
               --rm -i -t blockstream/esplora \
               bash -c "/srv/explorer/run.sh bitcoin-signet explorer"
  4. Access the Mempool explorer at http://localhost:80 or http://localhost:8084 (if using the direct docker run command)

Connecting Bitcoin Signet with Esplora

Note: If you're using Option 1 (root-level docker-compose.yml), the connection between Bitcoin Signet and Esplora is already configured and you can skip this section.

To ensure that Esplora can connect to your Bitcoin signet node when setting up components separately, you need to make sure they can communicate with each other:

  1. Network configuration:

    • If using Docker Compose for both services, create a shared network:
      docker network create bitcoin-network
    • Update both docker-compose files to use this network:
      networks:
        default:
          external:
            name: bitcoin-network
  2. Update Esplora's configuration to point to the Bitcoin signet RPC:

    • If using Docker Compose, add environment variables to Esplora's service:

      environment:
        - BITCOIND_URI=http://bitcoin:bitcoin@bitcoin-signet:38332
    • Make sure your Bitcoin signet node has RPC enabled and is accessible:

      rpcbind=0.0.0.0
      rpcallowip=0.0.0.0/0
      

Connecting Applications

You can connect various Bitcoin applications to your local signet:

Bitcoin Core

Configure Bitcoin Core to connect to your local signet:

signet=1
signetchallenge=<your-signet-challenge>
addnode=127.0.0.1:38333

Wallet Applications

Most wallet applications that support signet can be configured to connect to your local node:

Explorer Interfaces

This setup provides two different explorer interfaces, each with unique features:

Esplora Explorer (http://localhost:3001)

Esplora is a lightweight block explorer that provides:

  • Clean, minimalist interface
  • Basic transaction and block viewing
  • Address balance and history
  • Support for Segwit and Bech32 addresses
  • Advanced transaction view with script details
  • Mobile-friendly design

Mempool Dashboard (http://localhost:3002)

Mempool offers a more comprehensive view of the Bitcoin network:

  • Real-time mempool visualization
  • Fee estimation graphs
  • Block explorer with detailed statistics
  • Transaction acceleration
  • Lightning Network statistics (not applicable for signet)
  • Rich API for developers
  • Transaction tracking
  • Advanced visualization of blockchain data

Both explorers complement each other and provide different perspectives on the same blockchain data.

Learning Resources

Contributing

Contributions to improve the learning environment are welcome! Please feel free to submit pull requests or create issues with suggestions.

Troubleshooting

Common Issues

Esplora Shows "Currently Unavailable"

This typically happens when Esplora is trying to sync with the public signet chain instead of your local one:

  1. Ensure docker-compose.yml uses the correct network mode for Esplora:

    command:
      - bash
      - -c
      - '/srv/explorer/run.sh bitcoin-signet explorer nonverbose'  # Use signet, not regtest
  2. Check Bitcoin RPC connection:

    curl --user bitcoin:bitcoin --data-binary '{"jsonrpc":"1.0","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:38332
  3. Inspect Esplora logs:

    docker logs esplora

Mempool UI Not Loading Data

Mempool requires properly configured RPC connections to both Bitcoin and Esplora:

  1. Check whether Mempool API is connecting to Bitcoin:

    docker logs mempool-api | grep "mempool is now in sync"
  2. Look for Electrum connection errors:

    docker logs mempool-api | grep "Electrum error"
  3. Ensure all required environment variables are set in docker-compose.yml:

    MEMPOOL_BITCOIN_NETWORK: "signet"  # Match your Bitcoin node's network
    DATABASE_ENABLED: "true"
    MEMPOOL_BITCOIN_RPC_HOST: "bitcoin-miner"
    MEMPOOL_BITCOIN_RPC_PORT: "38332"
  4. Restart Mempool API after configuration changes:

    docker restart mempool-api

Understanding Component Architecture

  • Bitcoin Signet Node: Provides the blockchain and accepts transactions
  • Esplora: Indexes the blockchain and provides an Electrum server API on port 50001
  • Mempool UI: Consists of:
    • Database (MariaDB): Stores indexed data about blocks and transactions
    • Backend API: Connects to both Bitcoin (for mempool data) and Esplora (for blockchain data)
    • Frontend: Web interface that visualizes the data

Proper network connectivity between all components is crucial. The docker-compose.yml in this repository uses a shared network to ensure all services can communicate properly.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A plug-and-play Bitcoin infrastructure stack. Runs a full Bitcoin Core node with mining, Esplora explorer, and Mempool.space—all in one Docker Compose setup.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0