Canonical: https://solanashreds.xyz/learn/account-roles

# Signer, writable, readonly: how a message marks account roles

Solana writable accounts are set by three header counts that split the key list into signer, writable and readonly roles, and lookups extend it.

Solana writable accounts are not flagged one by one. The message header holds three counts that cut the ordered key list into four groups: writable signers, readonly signers, writable non-signers and readonly non-signers. A v0 transaction's looked-up accounts are never signers; the lookup tells you whether each is writable or readonly.

## The three header numbers

Every message starts with three bytes:

1. `num_required_signatures`: how many accounts must sign, counted from the start of the key list;
2. `num_readonly_signed_accounts`: how many of those signers are read only, counted from the end of the signer group;
3. `num_readonly_unsigned_accounts`: how many of the non-signers are read only, counted from the end of the static key list.

Because the key list is sorted into those four groups when the message is compiled, three counts are enough to give every static account its role.

## Role by position

With `n` static keys and header values `s`, `rs` and `ru`:

| Position | Role |
| --- | --- |
| 0 | the fee payer: always a writable signer |
| 1 to `s - rs - 1` | writable signers |
| `s - rs` to `s - 1` | readonly signers |
| `s` to `n - ru - 1` | writable non-signers |
| `n - ru` to `n - 1` | readonly non-signers |
| after the static keys (v0 only) | looked-up writable accounts, then looked-up readonly accounts |

## A real v0 transaction, role by role

This transaction from mainnet slot 470,901,816 has the header `1, 0, 6` and 21 static keys, plus two lookup tables.

| Group | Positions | Count |
| --- | --- | --- |
| Writable signer (fee payer) | 0 | 1 |
| Readonly signers | none | 0 |
| Writable non-signers | 1 to 14 | 14 |
| Readonly non-signers | 15 to 20 | 6 |
| Looked-up writable | 21 to 23 | 3 |
| Looked-up readonly | 24 to 39 | 16 |

Its one top-level program sits at position 15, in the readonly group, which is where compilers put programs that are only called. The same transaction's lookup tables are worked through on [address lookup tables](https://solanashreds.xyz/learn/address-lookup-tables).

## Roles for lookup keys

Accounts loaded through lookup tables come after all static keys, writable ones first, then readonly ones, across every table. None of them can sign: a signature must name an account in the static list, and lookups exist precisely to keep accounts out of it. So any account that needs to sign, including the fee payer, is always a static key.

## When writable is not really writable

The header gives the most an account may be. Two rules in the message code can lower it:

- protocol-reserved addresses, such as sysvars and built-in programs, are treated as readonly even if the header marks them writable;
- an account used as a program by one of the instructions is treated as readonly, unless the BPF upgradeable loader is also among the transaction's accounts.

So "writable by position" is a claim the runtime may narrow. For decoding that rarely matters; for anything that reasons about which accounts a transaction could change, apply both rules.

## Using roles to filter

Roles make cheap filters. The fee payer is position 0, so "transactions paid by this wallet" needs no instruction parsing. "Transactions that could change this pool" means the pool appears in a writable position. "Transactions this wallet signed" means it appears in the signer range. All three work on the static keys alone, compared as raw bytes rather than [base58 text](https://solanashreds.xyz/learn/base58-and-public-keys); only the writable-account filter needs lookups resolved for v0. [Filter by program ID and account](https://solanashreds.xyz/docs/decode/filter-by-program) builds on this, and [where to filter](https://solanashreds.xyz/blog/filter-early) discusses doing it as early as possible.

## Reading roles from shreds alone

Everything above comes from the transaction's own bytes, so it is available the moment a transaction is decoded from shreds. Roles of looked-up accounts need the tables, which is the one piece of outside state; [resolving lookup tables](https://solanashreds.xyz/docs/decode/resolve-lookup-tables) handles that. Roles say what a transaction may touch, which is often enough to route it before any decoding of instruction data.

## Questions about account roles

### Is the fee payer always the first account?

Yes. Position 0 is the fee payer, and it is always a writable signer.

### Can an account looked up from a table sign?

No. Signers are always static keys.

### Does writable mean the account was changed?

No. It means the transaction was allowed to change it. Whether it did depends on execution.

## What roles do not tell you

Roles describe permissions, not effects. A writable account may be left untouched, and roles say nothing about which instruction uses an account or why. They also need the transaction's full key list, so for v0 transactions with lookups, roles of the looked-up accounts are unknown until the tables are resolved.

## Where roles come into play

Roles sit inside the layout described in [what is inside a Solana transaction](https://solanashreds.xyz/learn/solana-transaction-structure), and instructions point into the same list, as [instruction data](https://solanashreds.xyz/learn/compiled-instructions) shows. To filter live traffic by role, [decode a first transaction from raw shreds](https://solanashreds.xyz/docs/quickstart).
