> 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/register-viewing-key.md).

# register\_viewing\_key

Register a 32-byte AES-256 viewing key in the Directory genesis contract for SRC20 event decryption.

## Signatures

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

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

## 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 the transaction     |
| `key`         | [`Bytes32`](/clients/python/api-reference/types/bytes32.md)        | Viewing key to register             |

## Returns

`HexBytes` — transaction hash.

## Example

```python
import os
from seismic_web3 import PrivateKey, Bytes32, SEISMIC_TESTNET
from seismic_web3.src20 import register_viewing_key

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

viewing_key = Bytes32(os.urandom(32))
tx_hash = register_viewing_key(w3, w3.seismic.encryption, pk, key=viewing_key)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Registered in block {receipt['blockNumber']}")
```

## Notes

* Uses a **shielded write** (`setKey(suint256)`) — the key is encrypted in transit
* Registering a new key overwrites the previous one
* The key is stored per `msg.sender` address
* `compute_key_hash(key)` returns the `keccak256` hash used for event topic filtering

## See Also

* [get\_viewing\_key](/clients/python/src20/intelligence-providers/get-viewing-key.md) — Fetch your viewing key back
* [check\_has\_key](/clients/python/src20/intelligence-providers/check-has-key.md) — Check if an address has a registered key


---

# 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/register-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.
