# Off-Chain Services Deployment - Quick Start

**Date**: 2026-01-18  
**Purpose**: Quick reference for deploying off-chain services

---

## Services Overview

### 1. State Anchoring Service

**Purpose**: Monitors ChainID 138 blocks and submits state proofs to MainnetTether  
**Location**: `services/state-anchoring-service/`  
**Guide**: [DEPLOYMENT.md](state-anchoring-service/DEPLOYMENT.md)

### 2. Transaction Mirroring Service

**Purpose**: Monitors ChainID 138 transactions and mirrors them to TransactionMirror  
**Location**: `services/transaction-mirroring-service/`  
**Guide**: [DEPLOYMENT.md](transaction-mirroring-service/DEPLOYMENT.md)

---

## Quick Deployment

### Prerequisites

```bash
# Node.js 18+ required
node --version

# Install dependencies for each service
cd services/state-anchoring-service && npm install && cd ../..
cd services/transaction-mirroring-service && npm install && cd ../..
```

### Environment Configuration

Create `.env` files in each service directory:

**State Anchoring Service** (`.env`):
```bash
PRIVATE_KEY=0x...
CHAIN138_RPC_URL=http://192.168.11.211:8545
MAINNET_RPC_URL=https://eth.llamarpc.com
TETHER_ADDRESS=0x15DF1D5BFDD8Aa4b380445D4e3E9B38d34283619
```

**Transaction Mirroring Service** (`.env`):
```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
```

### Build Services

```bash
# Build State Anchoring Service
cd services/state-anchoring-service
npm run build

# Build Transaction Mirroring Service
cd ../transaction-mirroring-service
npm run build
```

### Test Locally

```bash
# Test State Anchoring Service
cd services/state-anchoring-service
npm run dev

# Test Transaction Mirroring Service
cd ../transaction-mirroring-service
npm run dev
```

### Deploy to Production

#### Using PM2 (Recommended)

```bash
# Deploy State Anchoring Service
cd services/state-anchoring-service
pm2 start dist/index.js --name state-anchoring-service
pm2 save

# Deploy Transaction Mirroring Service
cd ../transaction-mirroring-service
pm2 start dist/index.js --name transaction-mirroring-service
pm2 save
```

#### Using Systemd

See individual deployment guides:
- [State Anchoring Service](state-anchoring-service/DEPLOYMENT.md#systemd-service-configuration)
- [Transaction Mirroring Service](transaction-mirroring-service/DEPLOYMENT.md#systemd-service-configuration)

---

## Monitoring

### Check Service Status

**PM2**:
```bash
pm2 status
pm2 logs state-anchoring-service
pm2 logs transaction-mirroring-service
```

**Systemd**:
```bash
sudo systemctl status state-anchoring-service
sudo systemctl status transaction-mirroring-service
sudo journalctl -u state-anchoring-service -f
sudo journalctl -u transaction-mirroring-service -f
```

### Verify Operation

**State Anchoring Service**:
```bash
# Check for state proofs on Mainnet
cast logs --address 0x15DF1D5BFDD8Aa4b380445D4e3E9B38d34283619 \
  --event "StateProofAnchored(uint256,bytes32,bytes32,uint256,uint256)" \
  --rpc-url https://eth.llamarpc.com | tail -20
```

**Transaction Mirroring Service**:
```bash
# Check TransactionMirror contract for mirrored transactions
cast call 0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9 \
  "processed(bytes32)" \
  "0x..." \
  --rpc-url https://eth.llamarpc.com
```

---

## Troubleshooting

### Service Won't Start

1. Check environment variables are set correctly
2. Verify RPC endpoints are accessible
3. Check private key format (must start with `0x`)
4. Verify wallet has sufficient ETH for gas

### No Data Being Submitted

1. Verify contract addresses are correct
2. Check RPC connectivity
3. Verify contract permissions
4. Check service logs for errors

### High Gas Costs

1. Adjust batch intervals
2. Reduce batch sizes
3. Monitor gas prices
4. Consider optimizing transaction batching

---

## Documentation

- [State Anchoring Service Deployment](state-anchoring-service/DEPLOYMENT.md)
- [Transaction Mirroring Service Deployment](transaction-mirroring-service/DEPLOYMENT.md)

---

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