Alchemy Web3: 多链区块链数据和 NFT API - Openclaw Skills

作者:互联网

2026-03-30

AI教程

什么是 Alchemy Web3?

Alchemy Web3 技能是一个为开发人员和 AI 智能体设计的生产级接口,用于与 80 多个区块链网络进行交互。通过将其集成到 Openclaw Skills 框架中,您可以立即访问以太坊、Polygon、Solana 和各种二层解决方案,而无需承担管理单个节点的开销。此技能充当检索实时链上数据的高性能桥梁,包括复杂的 NFT 元数据、ERC-20 代币余额和详细的交易历史。

它旨在支持手动 CLI 使用和自动化智能体工作流,简化了 JSON-RPC 调用和专有 NFT API 的复杂性。无论您是在构建投资组合追踪器还是自动化交易机器人,此技能都能提供现代去中心化应用所需的可靠数据骨干。

下载入口:https://github.com/openclaw/skills/tree/main/skills/gizmo-dev/alchemy-web3

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install alchemy-web3

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 alchemy-web3。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Alchemy Web3 应用场景

  • 监控跨多条链的巨鲸动态和巨额资产转移。
  • 自动检索画廊或市场应用的 NFT 元数据。
  • 构建多链投资组合追踪器,聚合来自以太坊、Base 和 Arbitrum 的余额。
  • 设置 Gas 价格监控,在最佳时间执行智能合约交互。
  • 通过 Webhook 将实时区块链事件通知集成到通信工具中。
Alchemy Web3 工作原理
  1. 用户提供 Alchemy API 密钥,该密钥安全地存储在本地环境配置中。
  2. 该技能利用统一的 CLI 封装器将高级命令转换为特定的 Alchemy API 请求。
  3. 请求根据指定的链参数(例如 eth-mainnet、base-sepolia)路由到相应的区块链端点。
  4. 技能处理响应,并在必要时处理十六进制值到人类可读数字的转换。
  5. 结构化 JSON 数据返回到 Openclaw Skills 环境,供智能体或开发人员立即使用。

Alchemy Web3 配置指南

要开始使用,请从 alchemy.com 获取 API 密钥并配置您的环境:

# 将您的 API 密钥添加到 ~/.openclaw/.env
ALCHEMY_API_KEY=your_api_key_here

# 可选:设置您的默认区块链网络
ALCHEMY_CHAIN=eth-mainnet

然后,您可以使用包含的脚本直接从终端运行查询:

./alchemy.sh balance 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045

Alchemy Web3 数据架构与分类体系

该技能将区块链数据组织成几个逻辑结构,以便于使用:

数据类别 描述 关键字段
余额 原生和 ERC-20 持仓 address, balance, symbol, decimals
NFT 元数据 详细的代币信息 contractAddress, tokenId, image, attributes
资产转移 历史交易流 from, to, value, asset, category
区块信息 网络级数据 blockNumber, hash, timestamp, transactions
ENS 以太坊域名服务 domain, address
name: alchemy-web3
version: 1.0.2
description: Interact with Alchemy's Web3 APIs for blockchain data, NFTs, tokens, transfers, and webhooks across 80+ chains.
author: GizmoLab
website: https://gizmolab.io?utm_source=alchemy-web3-skill&utm_medium=github&utm_campaign=skill
homepage: https://github.com/0xGizmolab/alchemy-web3-skill
repository: https://github.com/0xGizmolab/alchemy-web3-skill
metadata:
  {
    "openclaw":
      {
        "requires": { 
          "env": ["ALCHEMY_API_KEY"]
        }
      }
  }

Alchemy Web3 Skill

Query blockchain data, NFTs, tokens, and transfers using Alchemy's production-grade APIs. Supports Ethereum, Polygon, Arbitrum, Base, Solana, and 80+ other chains.

Built by GizmoLab — Web3 development agency specializing in dApps, smart contracts, and blockchain infrastructure.

Setup

1. Get API Key

  1. Sign up at alchemy.com (free tier available)
  2. Create an app for your target chain
  3. Copy your API key

?? New to Web3 development? GizmoLab offers full-stack blockchain development services.

2. Configure

# Add to ~/.openclaw/.env
ALCHEMY_API_KEY=your_api_key_here

# Optional: Set default chain (defaults to eth-mainnet)
ALCHEMY_CHAIN=eth-mainnet

Quick Reference

Supported Chains

Chain Endpoint Prefix
Ethereum eth-mainnet, eth-sepolia
Polygon polygon-mainnet, polygon-amoy
Arbitrum arb-mainnet, arb-sepolia
Optimism opt-mainnet, opt-sepolia
Base base-mainnet, base-sepolia
Solana solana-mainnet, solana-devnet
zkSync zksync-mainnet
Linea linea-mainnet
Scroll scroll-mainnet
Blast blast-mainnet

Full list: alchemy.com/docs/chains

CLI Usage

# Set your API key first
export ALCHEMY_API_KEY="your_key"

# Use the CLI
~/.openclaw/workspace/skills/alchemy-web3/scripts/alchemy.sh  [options]

Commands

Get ETH Balance

./alchemy.sh balance 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
# Returns: 1234.56 ETH

Get Token Balances

./alchemy.sh tokens 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
# Returns: All ERC-20 tokens held by address

Get NFTs for Owner

./alchemy.sh nfts 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
# Returns: All NFTs owned by address

Get NFT Metadata

./alchemy.sh nft-metadata 0x5180db8F5c931aaE63c74266b211F580155ecac8 1590
# Returns: Metadata for specific NFT

Get Asset Transfers

./alchemy.sh transfers 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
# Returns: Transaction history (in/out)

Get Block Info

./alchemy.sh block latest
./alchemy.sh block 12345678

Get Transaction

./alchemy.sh tx 0x123...abc

Resolve ENS

./alchemy.sh ens vitalik.eth
# Returns: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045

Switch Chain

./alchemy.sh --chain polygon-mainnet balance 0x...
./alchemy.sh --chain arb-mainnet nfts 0x...

Direct API Examples

Node API (JSON-RPC)

# Get ETH balance
curl -X POST "https://eth-mainnet.g.alchemy.com/v2/$ALCHEMY_API_KEY" r
  -H "Content-Type: application/json" r
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getBalance",
    "params": ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest"],
    "id": 1
  }'

NFT API

# Get NFTs for owner
curl "https://eth-mainnet.g.alchemy.com/nft/v3/$ALCHEMY_API_KEY/getNFTsForOwner?owner=vitalik.eth&pageSize=10"

# Get NFT metadata
curl "https://eth-mainnet.g.alchemy.com/nft/v3/$ALCHEMY_API_KEY/getNFTMetadata?contractAddress=0x5180db8F5c931aaE63c74266b211F580155ecac8&tokenId=1590"

# Get NFTs for collection
curl "https://eth-mainnet.g.alchemy.com/nft/v3/$ALCHEMY_API_KEY/getNFTsForContract?contractAddress=0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D&limit=10"

Token API

# Get token balances
curl -X POST "https://eth-mainnet.g.alchemy.com/v2/$ALCHEMY_API_KEY" r
  -H "Content-Type: application/json" r
  -d '{
    "jsonrpc": "2.0",
    "method": "alchemy_getTokenBalances",
    "params": ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"],
    "id": 1
  }'

# Get token metadata
curl -X POST "https://eth-mainnet.g.alchemy.com/v2/$ALCHEMY_API_KEY" r
  -H "Content-Type: application/json" r
  -d '{
    "jsonrpc": "2.0",
    "method": "alchemy_getTokenMetadata",
    "params": ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"],
    "id": 1
  }'

Transfers API

# Get asset transfers (transaction history)
curl -X POST "https://eth-mainnet.g.alchemy.com/v2/$ALCHEMY_API_KEY" r
  -H "Content-Type: application/json" r
  -d '{
    "jsonrpc": "2.0",
    "method": "alchemy_getAssetTransfers",
    "params": [{
      "fromBlock": "0x0",
      "toBlock": "latest",
      "toAddress": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
      "category": ["external", "erc20", "erc721", "erc1155"],
      "maxCount": "0x14"
    }],
    "id": 1
  }'

JavaScript/Node.js Examples

Using Fetch (Node 18+)

const apiKey = process.env.ALCHEMY_API_KEY;
const baseURL = `https://eth-mainnet.g.alchemy.com/v2/${apiKey}`;

// Get ETH Balance
async function getBalance(address) {
  const response = await fetch(baseURL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      jsonrpc: '2.0',
      method: 'eth_getBalance',
      params: [address, 'latest'],
      id: 1
    })
  });
  const data = await response.json();
  return parseInt(data.result, 16) / 1e18; // Convert to ETH
}

// Get NFTs
async function getNFTs(owner) {
  const url = `https://eth-mainnet.g.alchemy.com/nft/v3/${apiKey}/getNFTsForOwner?owner=${owner}`;
  const response = await fetch(url);
  return await response.json();
}

Using Alchemy SDK

npm install alchemy-sdk
import { Alchemy, Network } from 'alchemy-sdk';

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

// Get NFTs
const nfts = await alchemy.nft.getNftsForOwner('vitalik.eth');
console.log(nfts.ownedNfts);

// Get token balances
const balances = await alchemy.core.getTokenBalances('vitalik.eth');
console.log(balances);

// Get transaction history
const transfers = await alchemy.core.getAssetTransfers({
  toAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
  category: ['external', 'erc20']
});

Webhooks (Real-time Notifications)

Receive HTTP POST requests when onchain events happen.

Webhook Types

Type Use Case
Address Activity Track transfers to/from specific addresses
NFT Activity Track NFT sales, transfers, mints
Mined Transactions Track when your txs are mined
Dropped Transactions Get notified if tx is dropped
Gas Price Alert on gas price thresholds

Create Webhook (Dashboard)

  1. Go to dashboard.alchemy.com/webhooks
  2. Click "Create Webhook"
  3. Select type and configure
  4. Add your endpoint URL

Webhook Payload Example

{
  "webhookId": "wh_abc123",
  "id": "evt_xyz789",
  "createdAt": "2024-01-15T12:00:00.000Z",
  "type": "ADDRESS_ACTIVITY",
  "event": {
    "network": "ETH_MAINNET",
    "activity": [{
      "fromAddress": "0x123...",
      "toAddress": "0x456...",
      "value": 1.5,
      "asset": "ETH"
    }]
  }
}

Common Patterns

Portfolio Tracker

# Get all assets for a wallet
./alchemy.sh balance 0x...      # ETH balance
./alchemy.sh tokens 0x...       # ERC-20 tokens
./alchemy.sh nfts 0x...         # NFTs

Transaction History

# Get full tx history for address
./alchemy.sh transfers 0x... --category external,erc20,erc721

NFT Collection Analysis

# Get all NFTs in a collection
./alchemy.sh collection 0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D

Multi-chain Query

# Check same address across chains
for chain in eth-mainnet polygon-mainnet arb-mainnet base-mainnet; do
  echo "=== $chain ==="
  ./alchemy.sh --chain $chain balance 0x...
done

Rate Limits

Plan Compute Units/sec Monthly CUs
Free 330 300M
Growth 660 Unlimited
Scale Custom Custom

Most endpoints cost 1-50 CUs. Check alchemy.com/docs/rate-limits for details.

Error Handling

// Rate limited
{"error": {"code": 429, "message": "Too Many Requests"}}

// Invalid API key
{"error": {"code": 401, "message": "Invalid API Key"}}

// Invalid params
{"error": {"code": -32602, "message": "Invalid params"}}

Resources

  • Get API Key: alchemy.com (free tier)
  • Dashboard: dashboard.alchemy.com
  • Docs: alchemy.com/docs
  • SDK: github.com/alchemyplatform/alchemy-sdk-js
  • Status: status.alchemy.com

About

Built by GizmoLab ??

GizmoLab is a Web3 development agency building dApps, smart contracts, and blockchain tools.

  • ?? gizmolab.io — Agency services
  • ??? tools.gizmolab.io — Free blockchain dev tools
  • ?? ui.gizmolab.io — Web3 UI components

Need custom blockchain development? Get in touch

AI Agent Workflows

The skill is designed for both human developers AND AI agents. See references/agent-workflows.md for complete examples:

  • Whale Tracker — Monitor large wallets for moves
  • Portfolio Monitor — Track balances across chains
  • NFT Floor Alert — Alert on price drops
  • Token Change Detector — Detect incoming/outgoing tokens
  • Gas Optimizer — Wait for low gas to transact
  • Mint Detector — Watch for new NFT mints
  • Dashboard Generator — Auto-generate wallet dashboards

Agent Pattern

QUERY → STORE → ANALYZE → DECIDE → ACT → REPEAT

Example cron job for an agent:

# Every hour, check whale activity and alert if >100 ETH moved
0 * * * * ~/.openclaw/workspace/skills/alchemy-web3/scripts/whale-tracker.sh

See Also

  • references/nft-api.md - Full NFT API reference
  • references/token-api.md - Full Token API reference
  • references/node-api.md - Full Node API reference
  • references/chains.md - All supported chains
  • references/agent-workflows.md - AI agent automation examples