# Deployment Issues and Fixes

**Date**: 2025-12-11
**Status**: Deployment Attempted - Issues Identified

---

## ❌ Issues Found

### 1. Missing Environment Variables

**Issue**: `TETHER_ADMIN` and `MIRROR_ADMIN` are not set in `.env`

**Impact**: Deployment scripts require these addresses to deploy contracts

**Fix**: Add to `.env` file:
```bash
# Admin addresses (multisig recommended)
TETHER_ADMIN=0x...  # Replace with your multisig address
MIRROR_ADMIN=0x...  # Can be same as TETHER_ADMIN or different
```

---

### 2. RPC Authentication Error

**Issue**: `HTTP error 401 with body: Must be authenticated!`

**Impact**: Cannot connect to Ethereum Mainnet RPC endpoint

**Possible Causes**:
1. RPC URL placeholder not replaced (currently shows `YOUR_KEY`)
2. Invalid or expired API key
3. Missing authentication in RPC URL

**Fix**: Update `.env` file with valid RPC URL:
```bash
# Option 1: Alchemy (recommended)
ETH_MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_ACTUAL_API_KEY

# Option 2: Infura
ETH_MAINNET_RPC_URL=https://mainnet.infura.io/v3/YOUR_ACTUAL_PROJECT_ID

# Option 3: Other provider
ETH_MAINNET_RPC_URL=https://your-rpc-provider.com/YOUR_API_KEY
```

---

## ✅ Pre-Deployment Checklist

Before deploying, ensure:

- [ ] `TETHER_ADMIN` is set in `.env` (multisig recommended)
- [ ] `MIRROR_ADMIN` is set in `.env` (multisig recommended)
- [ ] `PRIVATE_KEY` is set in `.env` (deployer private key)
- [ ] `ETH_MAINNET_RPC_URL` is set with valid API key (not placeholder)
- [ ] `ETHERSCAN_API_KEY` is set in `.env`
- [ ] Deployer wallet has sufficient ETH for gas
- [ ] RPC endpoint is accessible and authenticated

---

## 🔧 Step-by-Step Fix

### Step 1: Update `.env` File

```bash
cd /home/intlc/projects/smom-dbis-138

# Edit .env file
nano .env  # or use your preferred editor

# Add/update these lines:
TETHER_ADMIN=0x...  # Your multisig address
MIRROR_ADMIN=0x...  # Your multisig address (can be same)
ETH_MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_ACTUAL_KEY
```

### Step 2: Verify Environment Variables

```bash
source .env
echo "Tether Admin: $TETHER_ADMIN"
echo "Mirror Admin: $MIRROR_ADMIN"
echo "RPC URL: $ETH_MAINNET_RPC_URL"
```

### Step 3: Test RPC Connection

```bash
cast block-number --rpc-url $ETH_MAINNET_RPC_URL
```

If this fails, check your RPC URL and API key.

### Step 4: Check Deployer Balance

```bash
cast balance $(cast wallet address $PRIVATE_KEY) --rpc-url $ETH_MAINNET_RPC_URL
```

Ensure you have sufficient ETH for gas (recommended: 0.1+ ETH).

---

## 🚀 Deployment Commands (After Fixes)

### Deploy MainnetTether

```bash
cd /home/intlc/projects/smom-dbis-138
source .env

forge script script/DeployMainnetTether.s.sol \
  --rpc-url $ETH_MAINNET_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast \
  --verify \
  -vvvv
```

### Deploy TransactionMirror

```bash
forge script script/DeployTransactionMirror.s.sol \
  --rpc-url $ETH_MAINNET_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast \
  --verify \
  --via-ir \
  -vvvv
```

---

## 📝 Notes

1. **Multisig Addresses**: Use Gnosis Safe or similar multisig for admin addresses
2. **Gas Costs**:
   - MainnetTether: ~1,200,000 gas (~$50-100 at current prices)
   - TransactionMirror: ~1,000,000 gas (~$40-80 at current prices)
3. **RPC Providers**:
   - Alchemy: https://www.alchemy.com/
   - Infura: https://www.infura.io/
   - QuickNode: https://www.quicknode.com/
4. **Verification**: Contracts will be automatically verified on Etherscan if `ETHERSCAN_API_KEY` is set

---

## 🔍 Troubleshooting

### Issue: "Must be authenticated" Error

**Solution**:
- Check RPC URL format
- Verify API key is correct
- Ensure API key has not expired
- Check if API key has Mainnet access enabled

### Issue: "Insufficient funds" Error

**Solution**:
- Add more ETH to deployer wallet
- Check current gas prices
- Consider deploying during low gas periods

### Issue: "Contract verification failed"

**Solution**:
- Check `ETHERSCAN_API_KEY` is set correctly
- Wait a few minutes and try manual verification
- Verify constructor arguments are correct

---

**Last Updated**: 2025-12-11
**Status**: Issues Identified - Fixes Provided
