# Bitcoin Node

{% tabs %}
{% tab title="Docker" %}
{% hint style="success" %}
**Минимальные требования к серверу:**

* **Диск:** Не менее 1 ТБ SSD (NVMe).
* **Процессор:** Минимум 6 ядер.
* **Память:** 8 ГБ.
* **Программное обеспечение:** Необходимо наличие установленного Docker.
  {% endhint %}

#### Создаем окружение:

```bash
mkdir -p /nodes/btc
```

```bash
cd /nodes/btc
```

#### Создаем дерикторию с данными bitcoind:

```bash
mkdir bitcoin_data
```

#### Создаем конфигурацию bitcoind:

```bash
nano bitcoind.conf
```

{% code title="bitcoind.conf" %}

```yaml
[main]
rpcallowip=0.0.0.0/0 # !ALLOWED IP!
rpcbind=0.0.0.0
rpcport=8332
rpcuser=YOUR_USER_NAME
rpcpassword=YOUR_PASSWORD
server=1
#txindex=1
prune=2048 #2GB
datadir=/data/.bitcoin
keypool=2000
```

{% endcode %}

#### Создаем docker-compose.yml

```bash
nano docker-compose.yml
```

{% code title="docker-compose.yml" %}

```yaml
x-logging:
  &default-logging
  driver: "json-file"
  options:
    max-file: "1"
    max-size: "500m"

services:
  bitcoin:
    image: rg.boxexchanger.net/boxexchanger-utils/docker-bitcoind:main
    container_name: bitcoind
    volumes:
      - ./bitcoin_data:/data/.bitcoin
      - ./bitcoind.conf:/data/bitcoind.conf
    logging: *default-logging
    restart: unless-stopped
    stop_grace_period: 15m30s
    ports:
      - "8333:8333"
      - "127.0.0.1:8332:8332"
```

{% endcode %}

#### Запускаем bitcoind в docker:&#x20;

```bash
docker compose up -d
```

{% endtab %}

{% tab title="Sources" %}

#### CMD:

```bash
sudo ufw allow 8332
mkdir /nodes
mkdir /nodes/BTC
sudo apt update
sudo apt install supervisor
```

#### /nodes/BTC/bitcoin.conf

```ini
[main]
rpcallowip=0.0.0.0/0 # !ALLOWED IP!
rpcbind=127.0.0.1
rpcport=8332
rpcuser=YOUR_USER_NAME
rpcpassword=YOUR_PASSWORD
server=1
#txindex=1
prune=2048 #2GB
datadir=/nodes/BTC
keypool=2000
```

#### /etc/supervisor/conf.d/bitcoind.conf

```ini
[program:bitcoind]
command=nice /usr/local/bin/bitcoind -conf=/nodes/BTC/bitcoin.conf
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/bitcoind.err.log
stdout_logfile=/var/log/supervisor/bitcoind.out.log
stderr_logfile_backups=2
stdout_logfile_backups=2
environment=HOME="/root"
```

#### CMD:&#x20;

```bash
sudo supervisorctl start bitcoind
sudo supervisorctl stop bitcoind
curl -#o /tmp/bitcoin.tar.gz https://bitcoin.org/bin/bitcoin-core-25.0/bitcoin-25.0-x86_64-linux-gnu.tar.gz
tar -xf /tmp/bitcoin.tar.gz -C /tmp/
cp /tmp/bitcoin-25.0/bin/bitcoind /usr/local/bin/bitcoind
rm -r /tmp/bitcoin-25.0
rm /tmp/bitcoin.tar.gz
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start bitcoind
```

{% endtab %}
{% endtabs %}

### Открываем порт доступа

Создаем прокси с портов \
&#x20; \- localhost:8332 на порт **8233** для bitcoind rpc&#x20;

<details>

<summary>Настраиваем прокси на caddy</summary>

Устанавливаем caddy <https://caddyserver.com/docs/install>\
\
Документация подготовлена для операционной системы **Debian, Ubuntu**

```shell
apt install -y debian-keyring debian-archive-keyring apt-transport-https
```

```shell
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
```

```shell
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' |  tee /etc/apt/sources.list.d/caddy-stable.list
```

```shell
apt update
```

```shell
apt install caddy
```

конфигурируем caddy  для прокси \
8332 на порт 8233 для внешней сети&#x20;

```bash
nano /etc/caddy/Caddyfile
```

{% code title="/etc/caddy/Caddyfile" %}

```nginx

:8233 {
  handle_path /* {
    reverse_proxy 127.0.0.1:8332
  }
  respond 404
}

```

{% endcode %}

запускаем caddy

```bash
systemctl enable --now caddy
```

или перезагружаем если необходимо&#x20;

`systemctl restart caddy`

</details>

{% hint style="warning" %}
**Открытие порта для RPC:** Для доступа к RPC необходимо открыть порт 8233 в настройках фаервола для IP-адреса сервера, с которого будет происходить подключение.
{% endhint %}

### Доступы

**RPC:** `http://ip.host:8233/`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.boxexchanger.net/dlya-razrabotchikov/ustanovka-node/bitcoin-node.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
