# Transaction Mirroring Service - Deployment Guide

**Date**: 2026-01-18  
**Status**: Ready for Deployment

---

## Overview

The Transaction Mirroring Service monitors ChainID 138 transactions and mirrors them to the TransactionMirror contract on Ethereum Mainnet.

**Location**: `services/transaction-mirroring-service/`  
**Implementation**: TypeScript (241 lines)  
**Status**: ✅ **READY FOR DEPLOYMENT**

---

## Prerequisites

1. **Node.js** 18+ installed
2. **TypeScript** compiler (tsc)
3. **Environment Variables**:
   - `PRIVATE_KEY` - Private key for signing transactions on Mainnet
   - `CHAIN138_RPC_URL` - RPC endpoint for ChainID 138
   - `MAINNET_RPC_URL` - RPC endpoint for Ethereum Mainnet
   - `MIRROR_ADDRESS` - TransactionMirror contract address

---

## Deployment Steps

### 1. Install Dependencies

```bash
cd services/transaction-mirroring-service
npm install
```

### 2. Configure Environment

Create `.env` file:

```bash
PRIVATE_KEY=0x...
CHAIN138_RPC_URL=http://192.168.11.211:8545
MAINNET_RPC_URL=https://eth.llamarpc.com
MIRROR_ADDRESS=0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9
BATCH_INTERVAL_MS=60000
```

### 3. Build Service

```bash
npm run build
```

### 4. Test Locally

```bash
npm run dev
```

### 5. Deploy to Production

```bash
# Using PM2 (recommended)
pm2 start dist/index.js --name transaction-mirroring-service

# Or using systemd (see below)
```

---

## Systemd Service Configuration

Create `/etc/systemd/system/transaction-mirroring-service.service`:

```ini
[Unit]
Description=Transaction Mirroring Service
After=network.target

[Service]
Type=simple
User=node
WorkingDirectory=/path/to/services/transaction-mirroring-service
Environment=NODE_ENV=production
ExecStart=/usr/bin/node dist/index.js
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

Enable and start:

```bash
sudo systemctl enable transaction-mirroring-service
sudo systemctl start transaction-mirroring-service
```

---

## Monitoring

### Check Service Status

```bash
# If using PM2
pm2 status transaction-mirroring-service
pm2 logs transaction-mirroring-service

# If using systemd
sudo systemctl status transaction-mirroring-service
sudo journalctl -u transaction-mirroring-service -f
```

### Verify Operation

Check TransactionMirror contract for mirrored transactions:

```bash
# Query contract for processed transactions
cast call 0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9 \
  "processed(bytes32)" \
  "0x..." \
  --rpc-url https://eth.llamarpc.com
```

---

## Configuration Options

### Environment Variables

| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `PRIVATE_KEY` | ✅ Yes | - | Private key for Mainnet transactions |
| `CHAIN138_RPC_URL` | ✅ Yes | `http://192.168.11.211:8545` | ChainID 138 RPC endpoint |
| `MAINNET_RPC_URL` | ✅ Yes | `https://eth.llamarpc.com` | Mainnet RPC endpoint |
| `MIRROR_ADDRESS` | ✅ Yes | `0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9` | TransactionMirror contract address |
| `BATCH_INTERVAL_MS` | No | `60000` | Batch interval in milliseconds |
| `MAX_BATCH_SIZE` | No | `100` | Maximum batch size |

### Service Configuration

The service monitors ChainID 138 transactions and batches them for efficiency. Configuration can be adjusted in `src/index.ts`:

- Batch interval
- Batch size
- Transaction filtering
- Retry logic

---

## Troubleshooting

### Service Not Starting

1. Check environment variables are set correctly
2. Verify RPC endpoints are accessible
3. Check private key format (must start with `0x`)

### No Transactions Being Mirrored

1. Verify TransactionMirror contract address is correct
2. Check wallet has sufficient ETH for gas
3. Verify contract has correct permissions
4. Check if transactions are being filtered

### Batch Size Issues

1. Adjust `MAX_BATCH_SIZE` if batching too many transactions
2. Adjust `BATCH_INTERVAL_MS` if batching too frequently
3. Monitor gas costs per batch

---

## Next Steps

After deployment:

1. Monitor service logs for errors
2. Verify transactions are being mirrored
3. Check TransactionMirror contract for new transactions
4. Set up alerts for service failures

---

**Last Updated**: 2026-01-18
