# Coinbase Wallet Agent

A **Bun-based Node.js service** that continuously listens for XMTP messages and processes them through the **Bitte AI API**.

{% embed url="<https://github.com/BitteProtocol/core-agent-tba>" %}

***

### ✨ Features

* **Real-time XMTP Integration**: Continuously listens for new XMTP messages
* **Bitte AI Processing**: Routes messages through Bitte AI agents for intelligent responses
* **Automatic Error Handling**: Handles errors gracefully and sends fallback responses
* **Key Generation Utility**: Script to generate wallet and encryption keys for setup

***

### 🛠️ Use Cases

* **XMTP Message Processing**: Real-time automated response to XMTP messages
* **AI Agent Proxy**: Bridge between XMTP and Bitte AI agents
* **Continuous Service**: Long-running service for persistent message handling

***

### 📦 Requirements

* [Bun](https://bun.sh/) (v1.0+)
* Node.js v20+

***

### ⚙️ Setup

#### 1. Install Dependencies

```bash
bun install
```

#### 2. Generate Keys (Optional for First-Time Setup)

```bash
bun scripts/gen-keys.ts
```

> This creates or appends to a `.env` file with `WALLET_KEY` and `ENCRYPTION_KEY`.

#### 3. Configure Environment Variables

Create a `.env` file in your project root:

```
WALLET_KEY=your_wallet_private_key
ENCRYPTION_KEY=your_encryption_key
BITTE_API_KEY=your_bitte_api_key
BITTE_AGENT_ID=your_bitte_agent_id
XMTP_ENV=dev
```

**Variable Reference:**

| Variable         | Description                                                    |
| ---------------- | -------------------------------------------------------------- |
| `WALLET_KEY`     | EVM private key (hex string, with or without `0x`)             |
| `ENCRYPTION_KEY` | 32-byte hex string for local DB encryption                     |
| `BITTE_API_KEY`  | Your Bitte API key (get from Bitte platform)                   |
| `BITTE_AGENT_ID` | Agent ID to route messages to (e.g. `coingecko-ai.vercel.app`) |
| `XMTP_ENV`       | XMTP environment (`dev`, `production`, etc.)                   |

***

### ▶️ Run the Service

#### Production

```bash
bun start
```

#### Development

```bash
bun dev
```

***

### 📜 Scripts

| Command                   | Description                                         |
| ------------------------- | --------------------------------------------------- |
| `bun start` / `bun dev`   | Start the XMTP message listener                     |
| `bun scripts/gen-keys.ts` | Generate wallet + encryption keys and update `.env` |

***

### 🧠 How It Works

1. **XMTP Setup**: Initializes XMTP client with wallet + encryption key
2. **Message Streaming**: Listens to incoming XMTP messages in real-time
3. **Message Processing**: Validates message sender + type
4. **AI Response**: Sends message to Bitte AI agent and gets a reply
5. **Reply**: Sends response back to original XMTP conversation
6. **Error Handling**: Logs errors and sends fallback replies if needed

***

### 🚀 Deployment

This is a long-running process. Recommended platforms:

* VPS / Dedicated server
* Docker container
* Railway, Fly.io, or DigitalOcean App Platform

***

### 🧰 Troubleshooting

* ✅ **Check Environment Variables**: Ensure `.env` is correctly configured
* 🔐 **Generate Keys**: Use `bun scripts/gen-keys.ts` if keys are missing
* 🧾 **Monitor Logs**: Console output gives insight into runtime behavior
* 🔑 **Bitte API Errors**: Double-check your API key + agent ID
* ♻️ **Restart on Failures**: Service continues running, but restart if persistent errors occur

***

### 📘 Notes

* This project uses **Bun** as the runtime.
* Use `.env.example` as a starting point for your configuration.
* See `XMTP_docs.md` for further XMTP details.
