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

# Install Bark Pay

> Run Bark Pay on your server with Docker Compose: configure the environment file, connect Barkd, start the stack, and sign in to the admin dashboard.

Bark Pay creates its Bark wallet on mainnet the first time it starts, so plan to [back up the wallet](/docs/bark-pay/backups) right after.

## Before you start

You need:

* A server with [Docker Engine](https://docs.docker.com/engine/install/) and the Docker Compose plugin, on x86\_64 or arm64.
* [Git](https://git-scm.com/downloads).
* A domain name pointing at the server.

<Accordion title="Deploying on Railway instead?">
  Follow the [Railway README](https://gitlab.com/ark-bitcoin/labs/bark-pay/-/tree/master/deploy/railway) in the repository, then continue with [Back up your wallet](/docs/bark-pay/backups).
</Accordion>

<Note>
  The values below connect Bark Pay to Second's mainnet Ark server, so charges move real bitcoin from the first sat. To try Bark Pay with test bitcoin first, [add test mode](#add-test-mode) once the stack runs.
</Note>

## Configure and start the stack

<Steps>
  <Step title="Clone the repository">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    git clone https://gitlab.com/ark-bitcoin/labs/bark-pay.git
    cd bark-pay
    ```
  </Step>

  <Step title="Create the environment file">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    cp .env.example .env
    ```
  </Step>

  <Step title="Set the public URL, the admin account, and the Ark endpoints">
    Open `.env` and delete the leading `#` from the two `BARKD_MAINNET_` lines, so they take effect. Replace `pay.example.com`, the email, and the password with your own, and leave both `BARKD_MAINNET_` URLs as shown. Leave the `#` in front of `BARKD_MAINNET_ACCESS_TOKEN`.

    ```bash .env theme={"theme":{"light":"github-light","dark":"github-dark"}}
    BARKPAY_PUBLIC_URL=https://pay.example.com
    BARKPAY_ADMIN_EMAIL=you@example.com
    BARKPAY_ADMIN_PASSWORD=<12 or more characters>

    BARKD_MAINNET_ARK_SERVER=https://ark.second.tech
    BARKD_MAINNET_ESPLORA=https://mempool.second.tech/api
    ```

    Bark Pay creates the admin account from these two values while no admin exists, and ignores them afterwards. The password needs 12 or more characters and can't contain a common word such as `password`, `admin`, or `barkpay`. Otherwise Bark Pay refuses to start.
  </Step>

  <Step title="Start Barkd">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker compose -f docker/docker-compose.prod.yml up -d --build barkd-mainnet
    ```
  </Step>

  <Step title="Copy the Barkd access token into .env">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker compose -f docker/docker-compose.prod.yml exec barkd-mainnet barkd secret show
    ```

    Paste the printed value into `.env` as `BARKD_MAINNET_ACCESS_TOKEN`.
  </Step>

  <Step title="Start Bark Pay">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker compose -f docker/docker-compose.prod.yml up -d --build
    ```

    The first build takes a few minutes.
  </Step>

  <Step title="Check that Bark Pay is ready">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    curl -s http://127.0.0.1:8080/ready
    ```

    The endpoint answers `{"status":"ready"}`. To follow the first start, run `docker compose -f docker/docker-compose.prod.yml logs -f bark-pay`.
  </Step>
</Steps>

<Note>
  Bark Pay only starts with the access token in `.env`. If you start the whole stack before copying it, the `bark-pay` container restarts in a loop until you add the token and run the start command again.
</Note>

## Serve Bark Pay over HTTPS

Bark Pay listens on plain HTTP on port 8080.

<Warning>
  Put Bark Pay behind HTTPS before you sign in. Over plain HTTP, your password travels unencrypted. Anyone who captures it can sign in and send payouts from your wallet.
</Warning>

<Tabs>
  <Tab title="Your own reverse proxy">
    Point your proxy (nginx, Traefik, or a Cloudflare tunnel) at port 8080 on the server, terminate TLS there, and set `BARKPAY_TRUSTED_PROXY_HOPS=2` in `.env`. Then recreate the container:

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker compose -f docker/docker-compose.prod.yml up -d bark-pay
    ```
  </Tab>

  <Tab title="Bundled Caddy">
    Let the Caddy bundled in the image obtain a Let's Encrypt certificate itself:

    <Steps>
      <Step title="Edit the Caddyfile">
        In `docker/Caddyfile`, replace `:{$PORT:8080}` with your domain and delete the `auto_https off` line.
      </Step>

      <Step title="Publish ports 80 and 443">
        In `docker/docker-compose.prod.yml`, replace the `ports` entry of the `bark-pay` service with `- "80:80"` and `- "443:443"`.
      </Step>

      <Step title="Rebuild">
        ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
        docker compose -f docker/docker-compose.prod.yml up -d --build
        ```
      </Step>
    </Steps>

    Leave `BARKPAY_TRUSTED_PROXY_HOPS=1` in `.env`.
  </Tab>
</Tabs>

## Sign in to the dashboard

Open your domain in a browser and sign in with the email and password from `.env`.

<Frame caption="After sign-in, Overview shows the wallet balance and the latest charges">
  <img src="https://mintcdn.com/second-0659a37d/w3x3inV3jE1Buo4A/images/bark-pay/overview.png?fit=max&auto=format&n=w3x3inV3jE1Buo4A&q=85&s=abfaced16950ec93d5efb2b30dcb7def" alt="Screenshot of the Bark Pay Overview page, with the My Bark Wallet balance card, the Today's volume card, and the Recent charges table" width="1320" height="1352" data-path="images/bark-pay/overview.png" />
</Frame>

## Add test mode

Test mode needs a second Barkd on signet:

<Steps>
  <Step title="Add a signet Barkd to the stack">
    In `docker/docker-compose.prod.yml`, copy the whole `barkd-mainnet` service under the name `barkd-signet`, point its volume at `barkd_signet_data`, and declare that volume next to the other two:

    ```yaml docker/docker-compose.prod.yml theme={"theme":{"light":"github-light","dark":"github-dark"}}
    volumes:
      barkpay_data:
      barkd_mainnet_data:
      barkd_signet_data:
    ```
  </Step>

  <Step title="Configure the signet instance in .env">
    Delete the leading `#` from the `BARKD_SIGNET_` lines, and leave these values as they are:

    ```bash .env theme={"theme":{"light":"github-light","dark":"github-dark"}}
    BARKD_SIGNET_URL=http://barkd-signet:3000
    BARKD_SIGNET_NETWORK=signet
    BARKD_SIGNET_ARK_SERVER=https://ark.signet.2nd.dev
    BARKD_SIGNET_ESPLORA=https://esplora.signet.2nd.dev
    ```
  </Step>

  <Step title="Start the signet Barkd">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker compose -f docker/docker-compose.prod.yml up -d --build barkd-signet
    ```
  </Step>

  <Step title="Copy its access token into .env">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker compose -f docker/docker-compose.prod.yml exec barkd-signet barkd secret show
    ```

    Paste the printed value into `.env` as `BARKD_SIGNET_ACCESS_TOKEN`.
  </Step>

  <Step title="Restart Bark Pay">
    ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker compose -f docker/docker-compose.prod.yml up -d bark-pay
    ```

    Bark Pay creates the signet wallet on this start. Switch to **Test mode** in the sidebar footer to work against it.
  </Step>
</Steps>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.