# Environment Variable Check - PRIVATE_KEY

**Date**: 2025-12-24  
**Purpose**: Check for PRIVATE_KEY in .env files

---

## Check Results

### .env File Status

**Location**: `/home/intlc/projects/proxmox/smom-dbis-138/.env`

**Status**: ⚠️ **.env file not found in repository**

**Note**: `.env` files are typically excluded from version control for security reasons.

---

## How to Check PRIVATE_KEY

### Method 1: Check if .env exists and contains PRIVATE_KEY

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

# Check if .env exists
if [ -f .env ]; then
    echo "✅ .env file exists"
    
    # Check if PRIVATE_KEY is set (without showing the value)
    if grep -q "^PRIVATE_KEY=" .env; then
        echo "✅ PRIVATE_KEY is set in .env"
        # Show first few characters for verification (optional)
        grep "^PRIVATE_KEY=" .env | sed 's/\(.\{10\}\).*/PRIVATE_KEY=\1...***HIDDEN***/'
    else
        echo "⚠️  PRIVATE_KEY is NOT set in .env"
    fi
else
    echo "⚠️  .env file does not exist"
    echo "Create it from .env.template if available"
fi
```

### Method 2: Check environment variable directly

```bash
# Check if PRIVATE_KEY is set in current environment
if [ -z "$PRIVATE_KEY" ]; then
    echo "⚠️  PRIVATE_KEY is not set in environment"
else
    echo "✅ PRIVATE_KEY is set in environment"
    # Get deployer address from private key
    cast wallet address $PRIVATE_KEY 2>/dev/null || echo "Invalid PRIVATE_KEY format"
fi
```

### Method 3: Check from deployment scripts

The deployment scripts expect PRIVATE_KEY to be set via:
- Environment variable: `export PRIVATE_KEY=<key>`
- .env file: `PRIVATE_KEY=<key>`
- Foundry's `vm.envUint("PRIVATE_KEY")` in scripts

---

## Expected Format

PRIVATE_KEY should be:
- **Without 0x prefix**: `1234567890abcdef...` (64 hex characters)
- **Or with 0x prefix**: `0x1234567890abcdef...` (66 characters total)

**Example**:
```bash
PRIVATE_KEY=1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
```

---

## Security Notes

⚠️ **NEVER commit .env files to version control**

The `.env` file should be in `.gitignore`:
```
.env
.env.local
.env.*.local
```

---

## Creating .env File

If `.env` doesn't exist, create it:

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

# Create .env file
cat > .env <<EOF
# Chain 138 RPC
RPC_URL_138=http://192.168.11.250:8545
RPC_URL=http://192.168.11.250:8545

# Deployer Private Key (REQUIRED)
PRIVATE_KEY=<your_private_key_here>

# Optional: Admin addresses (defaults to deployer if not set)
COMPLIANCE_ADMIN=
TOKEN_REGISTRY_OWNER=
FEE_COLLECTOR_OWNER=
EOF

# Set permissions (read-only for owner)
chmod 600 .env
```

---

## Verification

After setting PRIVATE_KEY, verify it works:

```bash
# Load .env
source .env

# Verify deployer address
DEPLOYER=$(cast wallet address $PRIVATE_KEY 2>/dev/null)
if [ -z "$DEPLOYER" ]; then
    echo "❌ Invalid PRIVATE_KEY"
else
    echo "✅ PRIVATE_KEY is valid"
    echo "Deployer address: $DEPLOYER"
    
    # Check balance
    BALANCE=$(cast balance $DEPLOYER --rpc-url $RPC_URL 2>/dev/null)
    echo "Balance: $BALANCE wei"
fi
```

---

## Next Steps

1. **If .env doesn't exist**: Create it with PRIVATE_KEY
2. **If PRIVATE_KEY not set**: Add it to .env or export it
3. **Verify**: Run verification commands above
4. **Deploy**: Run `./scripts/deploy-and-integrate-all.sh`

---

**Last Updated**: 2025-12-24

