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

> ## Agent Instructions
> Bitnob API requests authenticate with an `X-Auth-Client` API key header against https://api.bitnob.com.
> Always use the sandbox environment for testing. Never put live API keys in sample code.
> Money amounts are integers in the smallest unit of the currency (satoshis for BTC, cents for fiat). Never use floats.
> Every state-changing request takes a client-supplied `reference` and must be treated as idempotent on retry.
> Quotes expire. Re-quote rather than reusing a stale quote id.

# Module 2: Bitcoin Core architecture

> What a full node actually does, where Bitcoin Core keeps its data, and how RPC access is secured.

## Learning objectives

* Understand what it means to run a full Bitcoin node
* Know the difference between bitcoind and bitcoin-cli
* Identify where Bitcoin Core stores data (blocks, wallets, mempool)
* Understand how RPC access works and how to secure it

## Lesson outline

## What is a full node?

A full node:

* Validates every block and transaction
* Stores a full copy of the blockchain
* Participates in network consensus rules
* Enforces transaction policy (fees, size, etc.)

When you run bitcoind with default settings (mainnet), it:

* Connects to the peer-to-peer Bitcoin network
* Downloads and verifies all \~800GB of block data
* Stores this in a dedicated data directory

In regtest or testnet, it simulates this behavior on a smaller scale.

> [!NOTE]
>
> Full nodes are essential for decentralization, they enforce the rules of Bitcoin without trusting any third party.

## bitcoind vs bitcoin-cli

bitcoind: the daemon that runs the full Bitcoin node.

bitcoin-cli: the command-line client used to send RPC commands to bitcoind.

In regtest or testnet, it simulates this behavior on a smaller scale.

Example interaction:

* bitcoind -regtest -daemon
* bitcoin-cli -regtest getblockchaininfo

bitcoin-cli is just a frontend. It doesn’t do any validation. All the logic lives in the running bitcoind instance.

Tip:

Think of bitcoind as the server, and bitcoin-cli as your terminal-based admin tool.

Example interaction:

```bash theme={null}
bitcoind -regtest -daemon

bitcoin-cli -regtest getblockchaininfo
```

## Bitcoin Core data directory structure

By default:

* Linux: \~/.bitcoin/
* Regtest: \~/.bitcoin/regtest/
* Testnet: \~/.bitcoin/testnet3/

Key folders & files:

| File/dir | Purpose |
| - | - |
| blocks/ | Raw block data (.dat files) |
| chainstate/ | Fast-access database of current UTXO set |
| wallets/ | Wallet database files |
| mempool.dat | Unconfirmed transactions |
| debug.log | Node logs and errors |
| bitcoin.conf | Configuration file |

## Understanding the mempool

The mempool is Bitcoin Core’s memory-based pool of unconfirmed transactions.

It grows when blocks are full or fee pressure is high.

Use getrawmempool to view TXs in the pool:

```bash theme={null}
bitcoin-cli -regtest getrawmempool
```

In regtest, the mempool clears instantly when you mine blocks, useful for testing.

## Wallets in Bitcoin Core

Bitcoin Core now supports multi-wallet mode:

Each wallet has its own balance, address pool, and UTXOs.

Wallets are stored in: \~/.bitcoin/wallets/

You can create or load a wallet like this:

```bash theme={null}
bitcoin-cli -regtest createwallet "demo"

bitcoin-cli -regtest listwallets
```

> [!NOTE]
>
> Wallets must be loaded to access balances or send transactions.

## Permissioning and RPC ports

Default RPC Port:

* Mainnet : 8332
* Testnet : 18332
* Regtest : 18443

Authentication:

By default, Bitcoin Core uses .cookie file auth (preferred for security).

Or you can manually set rpcuser and rpcpassword in bitcoin.conf.

Example bitcoin.conf:

```plaintext theme={null}
server=1
rpcuser=admin
rpcpassword=supersecret
rpcallowip=127.0.0.1
```

**Security best practices:**

* Never expose RPC to the public internet
* bitcoind serves RPC over plain HTTP, so use an SSH tunnel or VPN if accessing over a network
* For Docker or remote CLI use: restrict to localhost or use SSH port forwarding

## Activity

Inspect your Bitcoin data directory:

1. Navigate to \~/.bitcoin/regtest/
2. List and describe what’s in blocks/, chainstate/, and wallets/
3. Run:

```bash theme={null}
bitcoin-cli -regtest getwalletinfo

bitcoin-cli -regtest getmempoolinfo
```


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