> For the complete documentation index, see [llms.txt](https://docs.zkbob.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zkbob.com/implementation/client-library-sdk/account-less-mode-operations/getting-the-state.md).

# Getting the State

The privacy pool's state is a set of the Merkle tree root and its current index ( additional details [here](/implementation/untitled.md)). The state is described by the [TreeState interface](/implementation/client-library-sdk/common-types.md#tree-state). In normal operations the client's local state should match both the relayer and the pool contract state. However there is no local state in the accountless mode, but we can monitor relayer and pool states.

The relayer node has two different states: the regular state (which should match the pool contract) and the optimistic one. The optimistic state contain transactions which will be included into the state but are not processed yet. In other words the optimistic state is a most likely future Merkle tree state. The optimistic index should always be greater or equal to the normal state.

The client local state should be up to date with the relayer state. Use the associated full-mode method [getLocalState(index?)](/implementation/client-library-sdk/full-mode-operations/account-state.md#getting-the-local-state) to retrieve.

## <mark style="background-color:green;">Get Pool Contract State</mark>

This is the primary state. All subsystems (relayer, client) must be synced with the pool state.

```typescript
async getPoolState(index?: bigint): Promise<TreeState>
```

### Parameters

`index` - the index of the merkle tree root to retrieve (use the latest index if undefined)&#x20;

### Returns

`Promise` returns [TreeState](/implementation/client-library-sdk/common-types.md#tree-state)

### Example

```typescript
const poolState = await zkClient.getPoolState();
console.log(`The pool contract actual state: ${poolState.root} @ ${poolState.index}`);
// output: The pool contract actual state:
// 20259123668790783065614334268308370728058669663334716067122266810210516357394 @ 533760
```

## <mark style="background-color:green;">Get Relayer State</mark>

This should match the pool state. Only the latest state can be requested, there is no way to specify an index.

```typescript
async getRelayerState(): Promise<TreeState>
```

### Returns

`Promise` returns [TreeState](/implementation/client-library-sdk/common-types.md#tree-state)

### Example

```typescript
const relayerState = await zkClient.getRelayerState();
console.log(`The relayer state: ${relayerState.root} @ ${relayerState.index}`);
// output: The relayer state:
// 20259123668790783065614334268308370728058669663334716067122266810210516357394 @ 533760
```

## <mark style="background-color:green;">Get Relayer Optimistic State</mark>

The forcasted state by the relayer. This can be used to monitor transaction queue length. The index of the optimistic state should be greater or equal the index of the current state.

```typescript
async getRelayerOptimisticState(): Promise<TreeState>
```

### Returns

`Promise` returns [TreeState](/implementation/client-library-sdk/common-types.md#tree-state)

### Example

```typescript
const opState = await zkClient.getRelayerOptimisticState();
console.log(`The relayer optimistic state: ${opState.root} @ ${opState.index}`);
// output: The relayer state:
// 12637519184649269054381762592793608281145118612151270269221975452396577578313 @ 533888
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.zkbob.com/implementation/client-library-sdk/account-less-mode-operations/getting-the-state.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
