# CCIP Bridge Quick Start

## Prerequisites

- Foundry installed (`cast` command available)
- Environment files configured (see templates)
- Bridge contracts deployed
- Admin private key with sufficient balance

## Quick Setup (5 Steps)

### 1. Setup Environment Files

```bash
cd terraform/phases/phase1/config

# Copy templates
cp env.mainnet.template ../../.env.mainnet
cp env.chain138.template ../../.env.chain138

# Edit with your values
nano ../../.env.mainnet
nano ../../.env.chain138
```

### 2. Configure Destinations (Chain 138 → Mainnet)

```bash
cd terraform/phases/phase1
source .env.chain138

# WETH9 bridge
export BRIDGE_ADDRESS=$CCIPWETH9_BRIDGE_CHAIN138
./scripts/ccip/ccip-configure-destination.sh \
    5009297550715157269 \
    0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6

# WETH10 bridge
export BRIDGE_ADDRESS=$CCIPWETH10_BRIDGE_CHAIN138
./scripts/ccip/ccip-configure-destination.sh \
    5009297550715157269 \
    0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e
```

### 3. Configure Destinations (Mainnet → Chain 138)

```bash
source .env.mainnet

# WETH9 bridge
export BRIDGE_ADDRESS=$CCIPWETH9_BRIDGE_MAINNET
./scripts/ccip/ccip-configure-destination.sh \
    $CHAIN138_SELECTOR \
    0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6

# WETH10 bridge
export BRIDGE_ADDRESS=$CCIPWETH10_BRIDGE_MAINNET
./scripts/ccip/ccip-configure-destination.sh \
    $CHAIN138_SELECTOR \
    0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e
```

### 4. Estimate Fee

```bash
source .env.chain138
export BRIDGE_ADDRESS=$CCIPWETH9_BRIDGE_CHAIN138

./scripts/ccip/ccip-estimate-fee.sh \
    5009297550715157269 \
    0xYourMainnetReceiverAddress \
    100000000000000000  # 0.1 WETH
```

### 5. Send Tokens

```bash
# First, approve bridge
cast send $WETH9_ADDRESS \
    "approve(address,uint256)(bool)" \
    $CCIPWETH9_BRIDGE_CHAIN138 \
    1000000000000000000 \
    --private-key $PRIVATE_KEY \
    --rpc-url $RPC_URL

# Then send
./scripts/ccip/ccip-send.sh \
    --selector 5009297550715157269 \
    --receiver 0xYourMainnetReceiverAddress \
    --amount 100000000000000000
```

## Verification

### Check Configuration

```bash
# Verify remote bridge is set
cast call $CCIPWETH9_BRIDGE_CHAIN138 \
    "remoteBridges(uint64)(address)" \
    5009297550715157269 \
    --rpc-url $RPC_URL
```

### Monitor Events

```bash
# Watch BridgedOut events
cast logs \
    --from-block latest \
    --address $CCIPWETH9_BRIDGE_CHAIN138 \
    "BridgedOut(uint64,address,address,uint256,bytes32)" \
    --rpc-url $RPC_URL
```

## Common Issues

**"BRIDGE_ADDRESS not set"**
- Export the bridge address: `export BRIDGE_ADDRESS=$CCIPWETH9_BRIDGE_CHAIN138`

**"Insufficient approval"**
- Approve bridge first: `cast send $WETH9_ADDRESS "approve(...)" ...`

**"Insufficient fee"**
- Check fee estimation and ensure bridge has enough LINK (if using LINK fees)

## Full Documentation

See `CCIP_BRIDGE_SETUP.md` for complete documentation.

