# Subnets and roles

## Subnets, Deployment, and Roles

This page explains how subnet registration works (MSB-side) and how admin/writer/indexer roles work (subnet-side).

### 1) Deploying a subnet (MSB registration)

Before contract txs can settle cleanly, the subnet must be registered in MSB.

On a running peer (typically the first node of the subnet), run:

```txt
/deploy_subnet
```

This broadcasts an MSB operation that registers:

* subnet bootstrap (`bs`)
* subnet channel (`ic` as a 32-byte identifier)

Peers can still replicate P2P without deploying, but MSB preflight checks and indexing behavior expect the subnet to exist in MSB state.

### 2) Admin role (subnet governance)

Subnet admin is stored inside the subnet state under:

* `admin`

On the bootstrap node, set the admin once:

```txt
/add_admin --address <peer-publicKey-hex>
```

Transfer admin later:

```txt
/update_admin --address <peer-publicKey-hex>
```

Verify:

```txt
/get --key admin --confirmed false
```

Notes:

* `--address` here is the **peer public key hex**, not a bech32 MSB address.

### 3) Writers vs indexers (Autobase roles)

Subnets use Autobase roles:

* **writers** can append subnet operations
* **indexers** participate in the linearization/indexing process (what advances the subnet’s signed/confirmed view)

#### Recommended indexer counts (rule of thumb)

How many peers you run depends on your application’s risk profile.

Rule of thumb:

* **Non-financial apps**: run **1 indexer**
* **Financial / “value” apps**: run **3 indexers**

For 3-indexer deployments, run them:

* in different datacenters/regions
* under different authorities/teams (if possible)

#### The first indexer is usually the admin

Operationally, the first node you bring up for a new subnet is typically:

* the subnet **admin** (governance)
* an **indexer** (so the subnet can actually produce confirmed state)

Admin commands:

```txt
/add_writer --key <writerKeyHex>
/remove_writer --key <writerKeyHex>

/add_indexer --key <writerKeyHex>
/remove_indexer --key <writerKeyHex>
```

Get your local writer key from:

```txt
/stats
```

### 4) Auto-add writers

Admins can allow nodes to become writers automatically when they join:

```txt
/set_auto_add_writers --enabled 1
```

This is subnet-scoped and only affects Autobase writer admission.

### 5) Transactions enabled switch

Subnets have a transactions gate:

* `txen` (transactions enabled)

Enable:

```txt
/enable_transactions
```

If disabled, subnet tx indexing and/or RPC tx submission will be blocked.

### 6) Chat system

The built-in chat system is off by default:

```txt
/set_chat_status --enabled 1
```

Post a message:

```txt
/post --message "hello"
```

Chat is a subnet feature. It does not move TNK; it only writes subnet state.

### 7) Confirmed vs unconfirmed subnet reads

When you query subnet state:

* `confirmed=false` reads the current local view (unsigned)
* `confirmed=true` reads the subnet’s signed view

These are properties of the subnet log/indexing, not “MSB settlement”.
