技能 编程开发 Web3应用云端部署集成

Web3应用云端部署集成

v20260423
alchemy-deploy-integration
用于安全地将依赖Alchemy服务的Web3应用(dApps)部署到主流云平台(如Vercel和Cloud Run)。该工具的核心功能是确保API密钥始终存储在服务器端,避免泄露到浏览器端,特别适用于需要后端服务调用区块链数据或设置RPC代理的生产环境部署场景。
获取技能
90 次下载
概览

Alchemy Deploy Integration

Overview

Deploy Alchemy-powered dApps with proper API key security. The API key must stay server-side — never ship it to the browser.

Instructions

Step 1: Vercel Deployment

# Add Alchemy API key as Vercel secret
vercel secrets add alchemy_api_key "your-api-key"
vercel link
vercel --prod
// vercel.json
{
  "env": { "ALCHEMY_API_KEY": "@alchemy_api_key" },
  "functions": { "api/**/*.ts": { "maxDuration": 30 } }
}
// api/balance/[address].ts — Vercel serverless function
import { Alchemy, Network } from 'alchemy-sdk';

const alchemy = new Alchemy({
  apiKey: process.env.ALCHEMY_API_KEY,
  network: Network.ETH_MAINNET,
});

export default async function handler(req: any, res: any) {
  const { address } = req.query;
  if (!/^0x[a-fA-F0-9]{40}$/.test(address)) {
    return res.status(400).json({ error: 'Invalid address' });
  }
  const balance = await alchemy.core.getBalance(address);
  res.json({ balance: balance.toString() });
}

Step 2: Cloud Run Deployment

# Build and deploy
gcloud builds submit --tag gcr.io/${PROJECT_ID}/alchemy-dapp
gcloud run deploy alchemy-dapp \
  --image gcr.io/${PROJECT_ID}/alchemy-dapp \
  --region us-central1 \
  --set-secrets=ALCHEMY_API_KEY=alchemy-api-key:latest \
  --allow-unauthenticated

Step 3: Health Check

// api/health.ts
import { Alchemy, Network } from 'alchemy-sdk';

export default async function handler(_req: any, res: any) {
  try {
    const alchemy = new Alchemy({ apiKey: process.env.ALCHEMY_API_KEY, network: Network.ETH_MAINNET });
    const block = await alchemy.core.getBlockNumber();
    res.json({ status: 'healthy', latestBlock: block });
  } catch {
    res.status(503).json({ status: 'unhealthy' });
  }
}

Output

  • Vercel deployment with API key in server-side functions
  • Cloud Run with GCP Secret Manager
  • Health check endpoint verifying Alchemy connectivity

Resources

Next Steps

For webhook handling, see alchemy-webhooks-events.

信息
Category 编程开发
Name alchemy-deploy-integration
版本 v20260423
大小 2.81KB
更新时间 2026-04-28
语言