> For the complete documentation index, see [llms.txt](https://docs.seismic.systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seismic.systems/clients/python/src20/intelligence-providers/get-viewing-key.md).

# get\_viewing\_key

Fetch your viewing key from the Directory genesis contract using signed read authentication.

## Signatures

```python
def get_viewing_key(
    w3: Web3,
    encryption: EncryptionState,
    private_key: PrivateKey,
) -> Bytes32

async def async_get_viewing_key(
    w3: AsyncWeb3,
    encryption: EncryptionState,
    private_key: PrivateKey,
) -> Bytes32
```

## Parameters

| Parameter     | Type                                                               | Description                         |
| ------------- | ------------------------------------------------------------------ | ----------------------------------- |
| `w3`          | `Web3` / `AsyncWeb3`                                               | Web3 instance with Seismic support  |
| `encryption`  | [`EncryptionState`](/clients/python/client/encryption-state.md)    | Encryption state from wallet client |
| `private_key` | [`PrivateKey`](/clients/python/api-reference/types/private-key.md) | Signing key for authentication      |

## Returns

[`Bytes32`](/clients/python/api-reference/types/bytes32.md) — 32-byte AES-256 viewing key.

Raises `ValueError` if no viewing key is registered for the caller's address.

## Example

```python
import os
from seismic_web3 import PrivateKey, SEISMIC_TESTNET
from seismic_web3.src20 import get_viewing_key

pk = PrivateKey.from_hex_str(os.environ["PRIVATE_KEY"])
w3 = SEISMIC_TESTNET.wallet_client(pk)

viewing_key = get_viewing_key(w3, w3.seismic.encryption, pk)
print(f"Viewing key: {viewing_key.hex()}")
```

## Notes

* Uses a **signed read** (`getKey()`) so that `msg.sender` is authenticated — only the key owner can retrieve it
* Typically called internally by [`watch_src20_events()`](/clients/python/src20/event-watching/watch-src20-events.md) to fetch the key before polling

## See Also

* [register\_viewing\_key](/clients/python/src20/intelligence-providers/register-viewing-key.md) — Register a viewing key
* [check\_has\_key](/clients/python/src20/intelligence-providers/check-has-key.md) — Check if an address has a key (public, no auth)
* [watch\_src20\_events](/clients/python/src20/event-watching/watch-src20-events.md) — Calls this internally


---

# 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.seismic.systems/clients/python/src20/intelligence-providers/get-viewing-key.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.
