# thirdweb Bridge - Quick Fix Guide

**What's Missing**: 5 Critical Requirements

---

## 🔴 CRITICAL: API Secret Key

**Problem**: `401 Unauthorized - Authentication required`

**Fix**:
1. Sign up: https://thirdweb.com
2. Dashboard → Settings → API Keys
3. Generate secret key
4. Export: `export THIRDWEB_SECRET_KEY=your_key`

**Test**:
```bash
THIRDWEB_SECRET_KEY=your_key ./scripts/test-thirdweb-bridge-with-auth.sh
```

---

## 🟡 HIGH: Chain Support Check

**Problem**: ChainID 138 may not be supported

**Fix**:
```bash
curl -X GET "https://api.thirdweb.com/v1/bridge/chains" \
  -H "x-secret-key: $THIRDWEB_SECRET_KEY" | jq '.[] | select(.chainId == 138)'
```

**If Not Supported**: Request support from thirdweb or use CCIP Bridge

---

## 🟡 HIGH: Correct API Format

**Problem**: Using wrong endpoint/format

**Wrong**:
```bash
POST https://bridge.thirdweb.com/api/quote
```

**Correct**:
```bash
POST https://api.thirdweb.com/v1/bridge/swap
Headers:
  - x-secret-key: <YOUR_KEY>
Body:
{
  "from": "0xWALLET",
  "exact": "input",
  "tokenIn": { "address": "...", "chainId": 138, "amount": "..." },
  "tokenOut": { "address": "...", "chainId": 1, "minAmount": "0" }
}
```

---

## 🟡 MEDIUM: Token Recognition

**Problem**: WETH may not be registered

**Check**:
```bash
curl -X GET "https://api.thirdweb.com/v1/bridge/tokens?chainId=138" \
  -H "x-secret-key: $THIRDWEB_SECRET_KEY" | jq '.[] | select(.address == "0xC02aaA39...")'
```

**If Not Recognized**: Contact thirdweb to register token

---

## 🟠 LOW: ERC-20 Metadata

**Problem**: `symbol()` and `decimals()` return unexpected values

**Impact**: May affect token recognition

**Fix Options**:
1. Fix contract metadata
2. Use WETH10 if it has correct metadata
3. Request thirdweb to accept token despite metadata issues

---

## Quick Test Script

**Ready-to-use script**: `scripts/test-thirdweb-bridge-with-auth.sh`

**Usage**:
```bash
THIRDWEB_SECRET_KEY=your_key \
WALLET_ADDRESS=0xYourWallet \
./scripts/test-thirdweb-bridge-with-auth.sh
```

**What it does**:
1. ✅ Checks chain support
2. ✅ Checks token recognition
3. ✅ Gets bridge quote

---

## Alternative: CCIP Bridge ✅

**If thirdweb Bridge requirements are too complex**:

**Use CCIP Bridge** (already available):
- ✅ No API keys needed
- ✅ Already deployed
- ✅ Supports ChainID 138
- ✅ Secure and audited

**Route**: Bridge WETH → Swap to USDT on Mainnet

---

## Priority Order

1. **Get API Key** (5 minutes)
2. **Check Chain Support** (1 minute)
3. **Update Script Format** (5 minutes)
4. **Test Quote** (1 minute)
5. **Fix Metadata** (if needed, hours/days)

**Total Time**: ~15 minutes (if chain supported)

---

**See**: `docs/THIRDWEB_BRIDGE_MISSING_REQUIREMENTS.md` for full details
