# What's Missing for thirdweb Bridge

**Date**: 2025-01-27  
**Route**: (ChainID 138, WETH) → (Ethereum Mainnet, USDT)  
**Status**: ❌ **Not Ready - Missing Requirements**

---

## Current Status

### ❌ What's Blocking thirdweb Bridge

1. **Authentication Required** - API requires secret key
2. **Chain Support Unknown** - ChainID 138 may not be supported
3. **Token Recognition** - WETH may not be registered/recognized
4. **API Endpoint Format** - Using incorrect endpoint/format

---

## Missing Requirements

### 1. API Authentication ❌ **CRITICAL**

**Issue**: API returns `401 Unauthorized - Authentication required`

**Required**:
- **Secret Key**: thirdweb Bridge API requires `x-secret-key` header
- **How to Get**: 
  1. Sign up for thirdweb account: https://thirdweb.com
  2. Navigate to Dashboard → Settings → API Keys
  3. Generate a secret key for Bridge API access

**Current Request** (Missing Auth):
```bash
curl -X POST "https://bridge.thirdweb.com/api/quote" \
  -H "Content-Type: application/json" \
  -d '{...}'
```

**Required Request** (With Auth):
```bash
curl -X POST "https://api.thirdweb.com/v1/bridge/swap" \
  -H "Content-Type: application/json" \
  -H "x-secret-key: <YOUR_SECRET_KEY>" \
  -d '{...}'
```

**Action Required**: 
- ✅ Obtain thirdweb API secret key
- ✅ Add to environment variables: `THIRDWEB_SECRET_KEY`
- ✅ Update scripts to include authentication header

---

### 2. Chain Support Verification ⚠️ **UNKNOWN**

**Issue**: ChainID 138 may not be supported by thirdweb Bridge

**Required Check**:
```bash
curl -X GET "https://api.thirdweb.com/v1/bridge/chains" \
  -H "x-secret-key: <YOUR_SECRET_KEY>"
```

**Expected Response**: List of supported chains with chain IDs

**What to Look For**:
- ChainID 138 in the supported chains list
- Chain name, native currency, RPC endpoints

**If ChainID 138 Not Supported**:
- ❌ Cannot use thirdweb Bridge for this route
- ✅ Use CCIP Bridge instead (already available)
- ⚠️ Contact thirdweb to request ChainID 138 support

**Action Required**:
- ✅ Check supported chains endpoint (with auth)
- ✅ Verify ChainID 138 is in the list
- ⚠️ If not supported, request support from thirdweb

---

### 3. Token Registration/Recognition ⚠️ **POTENTIAL ISSUE**

**Issue**: WETH token may not be recognized at canonical address

**Current Token**:
- **Address**: `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`
- **Issues Found**:
  - `symbol()` returns empty
  - `decimals()` returns 0 (should be 18)
  - `name()` returns empty

**Required Check**:
```bash
curl -X GET "https://api.thirdweb.com/v1/bridge/tokens?chainId=138" \
  -H "x-secret-key: <YOUR_SECRET_KEY>"
```

**What to Look For**:
- WETH token in the supported tokens list
- Token address matches canonical address
- Token metadata (symbol, decimals, name)

**If Token Not Recognized**:
- ❌ Bridge may reject the token
- ⚠️ May need to register token with thirdweb
- ⚠️ May need to fix ERC-20 metadata issues

**Action Required**:
- ✅ Check supported tokens endpoint (with auth)
- ✅ Verify WETH is recognized
- ⚠️ If not recognized, contact thirdweb to register token

---

### 4. Correct API Endpoint Format ⚠️ **INCORRECT**

**Issue**: Using wrong endpoint/request format

**Current Attempt** (Incorrect):
```bash
POST https://bridge.thirdweb.com/api/quote
{
  "fromChainId": 138,
  "toChainId": 1,
  "fromTokenAddress": "...",
  "toTokenAddress": "...",
  "amount": "..."
}
```

**Correct Format** (Based on thirdweb Documentation):
```bash
POST https://api.thirdweb.com/v1/bridge/swap
Headers:
  - Content-Type: application/json
  - x-secret-key: <YOUR_SECRET_KEY>
Body:
{
  "from": "0xYOUR_WALLET_ADDRESS",
  "exact": "input",  // or "output"
  "tokenIn": {
    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    "chainId": 138,
    "amount": "1000000000000000000"  // 1 WETH in wei
  },
  "tokenOut": {
    "address": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
    "chainId": 1,
    "minAmount": "..."  // Minimum USDT amount (for output-centric)
  }
}
```

**Key Differences**:
- ✅ Endpoint: `/v1/bridge/swap` (not `/api/quote`)
- ✅ Requires `from` wallet address
- ✅ Uses `tokenIn` and `tokenOut` objects
- ✅ Supports `exact: "input"` or `exact: "output"`

**Action Required**:
- ✅ Update scripts to use correct endpoint
- ✅ Use correct request format
- ✅ Include wallet address in request

---

### 5. ERC-20 Metadata Issues ⚠️ **POTENTIAL BLOCKER**

**Issue**: WETH contract has metadata issues

**Current Status**:
- ✅ `totalSupply()` works (20,014 WETH)
- ❌ `symbol()` returns empty
- ❌ `decimals()` returns 0 (should be 18)
- ❌ `name()` returns empty

**Impact**:
- Bridges may check `symbol()` or `decimals()` to recognize tokens
- If these fail, bridge may reject the token
- May need to fix contract or use different WETH version

**Possible Solutions**:
1. **Fix Contract**: Upgrade WETH contract to fix metadata
2. **Use Different Address**: If WETH10 has correct metadata, use that
3. **Contact thirdweb**: Request token recognition despite metadata issues

**Action Required**:
- ⚠️ Investigate why metadata functions return incorrect values
- ⚠️ Consider using WETH10 if it has correct metadata
- ⚠️ Test if bridge accepts token despite metadata issues

---

## Complete Checklist

### Immediate Actions Required

- [ ] **1. Obtain thirdweb API Secret Key**
  - Sign up at https://thirdweb.com
  - Generate secret key from dashboard
  - Store in environment: `THIRDWEB_SECRET_KEY`

- [ ] **2. Check Chain Support**
  ```bash
  curl -X GET "https://api.thirdweb.com/v1/bridge/chains" \
    -H "x-secret-key: $THIRDWEB_SECRET_KEY"
  ```
  - Verify ChainID 138 is in the list
  - If not, request support from thirdweb

- [ ] **3. Check Token Support**
  ```bash
  curl -X GET "https://api.thirdweb.com/v1/bridge/tokens?chainId=138" \
    -H "x-secret-key: $THIRDWEB_SECRET_KEY"
  ```
  - Verify WETH is recognized
  - Check if address matches canonical address

- [ ] **4. Update Scripts**
  - Add authentication header
  - Use correct endpoint: `/v1/bridge/swap`
  - Use correct request format
  - Include wallet address in request

- [ ] **5. Test Bridge Quote**
  ```bash
  curl -X POST "https://api.thirdweb.com/v1/bridge/swap" \
    -H "Content-Type: application/json" \
    -H "x-secret-key: $THIRDWEB_SECRET_KEY" \
    -d '{
      "from": "0xYOUR_WALLET",
      "exact": "input",
      "tokenIn": {
        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "chainId": 138,
        "amount": "1000000000000000000"
      },
      "tokenOut": {
        "address": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
        "chainId": 1,
        "minAmount": "0"
      }
    }'
  ```

- [ ] **6. Fix ERC-20 Metadata (If Needed)**
  - Investigate why `symbol()` and `decimals()` fail
  - Consider contract upgrade
  - Test with WETH10 if available

---

## Alternative: Use CCIP Bridge ✅

**If thirdweb Bridge requirements cannot be met**:

**Recommended**: Use CCIP Bridge (already available and working)

**Route**:
```
ChainID 138 (WETH) 
  → CCIP Bridge 
  → Ethereum Mainnet (WETH) 
  → Swap 
  → Ethereum Mainnet (USDT)
```

**Advantages**:
- ✅ Already deployed and configured
- ✅ No API keys required
- ✅ Secure and audited (Chainlink)
- ✅ Supports ChainID 138
- ✅ Works with current WETH contract

---

## Summary

### What's Missing (Priority Order)

1. **🔴 CRITICAL**: API Secret Key (authentication)
2. **🟡 HIGH**: Chain Support Verification (ChainID 138)
3. **🟡 HIGH**: Correct API Endpoint Format
4. **🟡 MEDIUM**: Token Recognition Check
5. **🟠 LOW**: ERC-20 Metadata Fix (if needed)

### Estimated Time to Fix

- **With API Key**: 1-2 hours (if chain/token supported)
- **Without Chain Support**: Requires thirdweb to add ChainID 138 (weeks/months)
- **Alternative (CCIP)**: Ready now ✅

### Recommendation

**Short-term**: Use CCIP Bridge (immediate solution)  
**Long-term**: Obtain thirdweb API key and verify support, then implement if viable

---

**Last Updated**: 2025-01-27  
**Next Action**: Obtain thirdweb API secret key and verify chain/token support
