> For the complete documentation index, see [llms.txt](https://wiki.4thtech.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.4thtech.io/sdk/ethereum/chat.md).

# Chat

Class that handles sending, retrieving and listening for events related to chat on-chain storage.

### Usage

Below is a minimal example of how to initialize Chat (with no optional parameters). It's highly recommended to also use your own appId.

```ts
import { Chat } from '@4thtech-sdk/ethereum';

const chat = new Chat({
  walletClient,
});
```

### Parameters

#### config

* **Type** `ChatConfig`

The configuration object required to initialize the chat client.

#### config.walletClient

* **Type** `WalletClient`

An instance of the wallet client that takes care of sending Ethereum transactions.

#### config.appId (Optional)

* **Type** `AppId`
* **Default** `0x0000000000000000000000000000000000000000000000000000000000000000`

A unique identifier for your application.

Application ID is used to effectively store and retrieve chat related data based on ID. Without an assigned App ID, it defaults to "zero". When multiple apps uses the same ID, all chat data are shared in all those apps.

If you register your own app, you can set up an integrator fee which will be charged on every sent message.

```ts
const chat = new Chat({
  walletClient,
  appId,
});
```

#### config.encryptor (Optional)

* **Type** `Encryptor`

A service that is optionally used for the encryption and decryption of chat messages.

If you wish to encrypt and decrypt chat messages, it's crucial to provide an `Encryptor` service for this purpose.

```ts
const chat = new Chat({
  walletClient,
  encryptor,
});
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://wiki.4thtech.io/sdk/ethereum/chat.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
