alchemy-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAlchemy API (with API Key)
Alchemy API(使用 API Key)
Reference and integration guide for wiring Alchemy APIs into application code using a standard API key. This file alone is enough to ship a basic integration; the directory contains deeper coverage of every product surface.
references/使用标准 API Key 将 Alchemy API 接入应用程序代码的参考与集成指南。仅凭本文件即可交付基础集成; 目录则提供了所有产品领域的深入说明。
references/When to use this skill
何时使用此 Skill
Use when all of the following are true:
alchemy-api- The user is wiring Alchemy into application code (server, backend, dApp, worker, script) that runs outside the current agent session
- They have, or are willing to create, an Alchemy API key (free at dashboard.alchemy.com)
This is the preferred app-integration path for normal server/backend usage.
当满足以下所有条件时,使用 :
alchemy-api- 用户正在将 Alchemy 接入在当前 Agent 会话之外运行的应用程序代码(服务器、后端、dApp、Worker、脚本)
- 用户已经拥有或愿意创建 Alchemy API Key(可在 dashboard.alchemy.com 免费获取)
对于常规服务器/后端场景,这是首选的应用集成路径。
When to use a different skill
何时使用其他 Skill
| Situation | Use this skill instead |
|---|---|
Live agent work in this session (queries, admin, on-machine automation) and | |
| Live agent work in this session and only MCP is wired into the client (no CLI) | |
| Live agent work and neither is available | install |
| Application code without an API key — autonomous agent paying per-request, or user explicitly wants x402/MPP | |
Do not use this skill to run ad-hoc live queries from inside the agent session — that's the / path. This skill is for code that ships.
alchemy-clialchemy-mcp| 情况 | 改用此 Skill |
|---|---|
在当前会话中执行实时 Agent 工作(查询、管理操作、本机自动化),且本地已安装 | |
| 在当前会话中执行实时 Agent 工作,但客户端仅接入 MCP(无 CLI) | |
| 在当前会话中执行实时 Agent 工作,但两者均不可用 | 安装 |
| 无 API Key 的应用程序代码——自主 Agent 按请求付费,或用户明确要求使用 x402/MPP | |
不要使用此 Skill 在 Agent 会话内执行临时实时查询——这类任务应使用 / 路径。此 Skill 专用于可交付的代码。
alchemy-clialchemy-mcpMandatory preflight gate
强制预检门禁
Before writing application code or making any network call:
- Confirm the user is building application code (not asking the agent to run a live query). If the user is asking for live work, redirect to (preferred) or
alchemy-cli.alchemy-mcp - Check is set (e.g.
$ALCHEMY_API_KEY).echo $ALCHEMY_API_KEY - If is unset or empty, take the first of these that applies:
$ALCHEMY_API_KEY- CLI bridge (recommended if is installed locally): the CLI can fetch a key from the user's Alchemy account so they never have to leave the terminal. See Bridging from the CLI to an API key below.
@alchemy/cli - Tell the user they can create a free API key at https://dashboard.alchemy.com/, or
- Switch to the skill (x402/MPP gateway, wallet-based auth, no API key needed).
agentic-gateway
- CLI bridge (recommended if
You MUST NOT call any keyless or public fallback (including ) unless the user explicitly asks for that endpoint. No public RPC endpoints (publicnode, llamarpc, cloudflare-eth, etc.) as a fallback.
.../v2/demo在编写应用程序代码或发起任何网络调用之前:
- 确认用户是在构建应用程序代码(而不是要求 Agent 执行实时查询)。如果用户要求执行实时任务,则转交给 (首选)或
alchemy-cli。alchemy-mcp - 检查 是否已设置(例如
$ALCHEMY_API_KEY)。echo $ALCHEMY_API_KEY - 如果 未设置或为空,则采用以下方案中适用的第一个:
$ALCHEMY_API_KEY- CLI 桥接(当本地已安装 时推荐): CLI 可以从用户的 Alchemy 账户获取 Key,因此用户无需离开终端。详见下方从 CLI 桥接到 API Key。
@alchemy/cli - 告知用户可以在 https://dashboard.alchemy.com/ 创建免费 API Key;或者
- 切换到 Skill(x402/MPP 网关、基于钱包的鉴权、无需 API Key)。
agentic-gateway
- CLI 桥接(当本地已安装
除非用户明确要求使用无密钥或公共回退端点(包括 ),否则不得调用任何无密钥或公共回退端点。也不得使用公共 RPC 端点(publicnode、llamarpc、cloudflare-eth 等)作为回退方案。
.../v2/demoBridging from the CLI to an API key
从 CLI 桥接到 API Key
If is installed locally (verify with ), use it to obtain a key without leaving the terminal and persist it to the project's file so it survives across terminal sessions and is available to the app at runtime.
@alchemy/clicommand -v alchemy.envSecurity: NEVER echo, print, or otherwise surface the extracted API key value in conversation output. Refer to it only asafter exporting. Treat it the same as a password.$ALCHEMY_API_KEY
bash
undefined如果本地已安装 (通过 验证),可以使用它获取 Key 而无需离开终端,并将其持久化到项目的 文件,以便跨终端会话保留,并在应用运行时可用。
@alchemy/clicommand -v alchemy.env安全要求: 切勿在对话输出中回显、打印或以其他方式暴露提取到的 API Key 值。导出后,仅将其引用为。应将其视为密码。$ALCHEMY_API_KEY
bash
undefined1. Try to read a cached key from the CLI config (read-only, safe to run non-interactively).
1. Try to read a cached key from the CLI config (read-only, safe to run non-interactively).
KEY="$(alchemy --no-interactive --json --reveal config get api-key 2>/dev/null | jq -r .value)"
KEY="$(alchemy --no-interactive --json --reveal config get api-key 2>/dev/null | jq -r .value)"
2. If empty/null (no key cached yet), run the interactive flow.
2. If empty/null (no key cached yet), run the interactive flow.
Note: auth login opens a browser and apps select shows a picker, so do NOT pass
Note: auth login opens a browser and apps select shows a picker, so do NOT pass
--no-interactive here. If you already know the app id, pass it explicitly to skip
--no-interactive here. If you already know the app id, pass it explicitly to skip
the picker: alchemy --no-interactive --json apps select <id>
.
alchemy --no-interactive --json apps select <id>the picker: alchemy --no-interactive --json apps select <id>
.
alchemy --no-interactive --json apps select <id>if [ -z "$KEY" ] || [ "$KEY" = "null" ]; then
alchemy auth login # opens browser; derives auth credentials
alchemy --json apps select # interactive picker (omit --no-interactive so it can render)
KEY="$(alchemy --no-interactive --json --reveal config get api-key | jq -r .value)"
fi
if [ -z "$KEY" ] || [ "$KEY" = "null" ]; then
alchemy auth login # opens browser; derives auth credentials
alchemy --json apps select # interactive picker (omit --no-interactive so it can render)
KEY="$(alchemy --no-interactive --json --reveal config get api-key | jq -r .value)"
fi
3. Persist to the project's .env (standard practice for app code so the key
3. Persist to the project's .env (standard practice for app code so the key
survives terminal restarts and is loaded by dotenv / framework env loaders).
survives terminal restarts and is loaded by dotenv / framework env loaders).
Use .env.local instead if your framework expects that (e.g. Next.js).
Use .env.local instead if your framework expects that (e.g. Next.js).
ENV_FILE=".env" # or ".env.local" depending on the project convention
touch "$ENV_FILE"
if grep -q '^ALCHEMY_API_KEY=' "$ENV_FILE"; then
Replace existing line in-place (portable across BSD/GNU sed)
sed -i.bak "s|^ALCHEMY_API_KEY=.*|ALCHEMY_API_KEY=$KEY|" "$ENV_FILE" && rm "$ENV_FILE.bak"
else
echo "ALCHEMY_API_KEY=$KEY" >> "$ENV_FILE"
fi
ENV_FILE=".env" # or .env.local depending on the project convention
touch "$ENV_FILE"
if grep -q '^ALCHEMY_API_KEY=' "$ENV_FILE"; then
Replace existing line in-place (portable across BSD/GNU sed)
sed -i.bak "s|^ALCHEMY_API_KEY=.*|ALCHEMY_API_KEY=$KEY|" "$ENV_FILE" && rm "$ENV_FILE.bak"
else
echo "ALCHEMY_API_KEY=$KEY" >> "$ENV_FILE"
fi
4. Make sure the env file is git-ignored.
4. Make sure the env file is git-ignored.
grep -qxF "$ENV_FILE" .gitignore 2>/dev/null || echo "$ENV_FILE" >> .gitignore
grep -qxF "$ENV_FILE" .gitignore 2>/dev/null || echo "$ENV_FILE" >> .gitignore
5. Also export to the current shell so the agent can immediately call the API.
5. Also export to the current shell so the agent can immediately call the API.
export ALCHEMY_API_KEY="$KEY"
> **Why we persist to `.env`:** without it, the key is only set for the current shell session and disappears when the terminal tab closes. App code typically loads `.env` via `dotenv` (Node), `python-dotenv` (Python), `direnv`, or framework-native loaders (Next.js, Vite, Bun, Deno, Rails, etc.), so writing to `.env` is the canonical way to make the key durable for both `npm run dev` and the deployed app's local copy.
> **Why this whole flow works:** the CLI is a runtime executor (`alchemy-cli` skill). When the user has it installed, you can use it to provision the credential that this app-code skill needs, write it to a place the application will load, then hand off to the rest of the `alchemy-api` flow. After step 5, continue with the [Base URLs + auth](#base-urls--auth-cheat-sheet) and [Quickstart](#one-file-quickstart-copypaste) below.
> **Gotcha:** if `auth login` succeeded but `config get api-key` still returns "not found," the CLI's `setup status` may have falsely reported `complete: true` with only an `auth_token`. Re-run `alchemy --json apps select` (or pass an explicit `<id>` with `--no-interactive`) to bind a default app, then retry. See the `alchemy-cli` skill for the same gotcha documented under Preflight.export ALCHEMY_API_KEY="$KEY"
> **为什么持久化到 `.env`:** 如果不进行持久化,Key 只会在当前 Shell 会话中设置,并在关闭终端标签页后消失。应用程序代码通常会通过 `dotenv`(Node)、`python-dotenv`(Python)、`direnv` 或框架原生加载器(Next.js、Vite、Bun、Deno、Rails 等)从 `.env` 加载配置,因此将 Key 持久化到 `.env` 是确保其在 `npm run dev` 以及已部署应用的本地副本中均可用的标准方式。
> **整个流程之所以有效的原因:** CLI 是一个运行时执行器(`alchemy-cli` Skill)。当用户已安装 CLI 时,可以使用它配置此应用程序代码 Skill 所需的凭据,将凭据写入应用程序会加载的位置,然后继续执行其余 `alchemy-api` 流程。完成第 5 步后,继续阅读[基础 URL 与鉴权速查表](#基础-url-与鉴权速查表)和[单文件快速入门](#单文件快速入门复制粘贴)。
> **常见问题:** 如果 `auth login` 成功,但 `config get api-key` 仍返回“not found”,则 CLI 的 `setup status` 可能仅因存在 `auth_token` 而错误报告 `complete: true`。重新运行 `alchemy --json apps select`(或使用 `--no-interactive` 显式传入 `<id>`)以绑定默认应用,然后重试。`alchemy-cli` Skill 的 Preflight 部分记录了相同问题。Summary
概述
A self-contained guide for AI agents integrating Alchemy APIs using an API key. This file alone should be enough to ship a basic integration. Use the reference files for depth, edge cases, and advanced workflows.
Developers can always create a free API key at https://dashboard.alchemy.com/.
这是一份面向使用 API Key 集成 Alchemy API 的 AI Agent 的独立指南。仅凭本文件应足以交付基础集成。深度内容、边缘情况和高级工作流请参阅参考文件。
开发者始终可以在 https://dashboard.alchemy.com/ 创建免费 API Key。
Do this first
优先执行以下步骤
- Confirm app-integration scope (see Mandatory preflight gate).
- Choose the right product using the Endpoint selector below.
- Use the Base URLs + auth table for the correct endpoint and headers.
- Copy a Quickstart example and test against a testnet first.
- 确认应用集成范围(参见强制预检门禁)。
- 使用下方的端点选择器(常见任务)选择正确的产品。
- 使用基础 URL 与鉴权速查表获取正确的端点和请求头。
- 复制一份单文件快速入门示例,并首先在测试网上进行测试。
Base URLs + auth (cheat sheet)
基础 URL 与鉴权速查表
| Product | Base URL | Auth | Notes |
|---|---|---|---|
| Ethereum RPC (HTTPS) | | API key in URL | Standard EVM reads and writes. |
| Ethereum RPC (WSS) | | API key in URL | Subscriptions and realtime. |
| Base RPC (HTTPS) | | API key in URL | EVM L2. |
| Base RPC (WSS) | | API key in URL | Subscriptions and realtime. |
| Arbitrum RPC (HTTPS) | | API key in URL | EVM L2. |
| Arbitrum RPC (WSS) | | API key in URL | Subscriptions and realtime. |
| BNB RPC (HTTPS) | | API key in URL | EVM L1. |
| BNB RPC (WSS) | | API key in URL | Subscriptions and realtime. |
| Solana RPC (HTTPS) | | API key in URL | Solana JSON-RPC. |
| Solana Yellowstone gRPC | | | gRPC streaming (Yellowstone). |
| Sui gRPC | | | Sui gRPC API (objects, txs, balances, streaming). |
| Notify API | | | Generate token in dashboard. |
| 产品 | 基础 URL | 鉴权 | 备注 |
|---|---|---|---|
| Ethereum RPC(HTTPS) | | URL 中包含 API Key | 标准 EVM 读写。 |
| Ethereum RPC(WSS) | | URL 中包含 API Key | 订阅与实时数据。 |
| Base RPC(HTTPS) | | URL 中包含 API Key | EVM L2。 |
| Base RPC(WSS) | | URL 中包含 API Key | 订阅与实时数据。 |
| Arbitrum RPC(HTTPS) | | URL 中包含 API Key | EVM L2。 |
| Arbitrum RPC(WSS) | | URL 中包含 API Key | 订阅与实时数据。 |
| BNB RPC(HTTPS) | | URL 中包含 API Key | EVM L1。 |
| BNB RPC(WSS) | | URL 中包含 API Key | 订阅与实时数据。 |
| Solana RPC(HTTPS) | | URL 中包含 API Key | Solana JSON-RPC。 |
| Solana Yellowstone gRPC | | | gRPC 流式传输(Yellowstone)。 |
| Sui gRPC | | | Sui gRPC API(对象、交易、余额、流式传输)。 |
| Notify API | | | 在控制台中生成 Token。 |
Endpoint selector (top tasks)
端点选择器(常见任务)
| You need | Use this | Skill / file |
|---|---|---|
| EVM read/write | JSON-RPC | |
| Realtime events | | |
| Simulate tx | | |
| Create webhook | | |
| Solana DAS | | |
| Sui objects/txs | | |
| Sui balances | | |
| Sui checkpoints stream | | |
| 需求 | 使用 | Skill / 文件 |
|---|---|---|
| EVM 读写 | JSON-RPC | |
| 实时事件 | | |
| 模拟交易 | | |
| 创建 Webhook | | |
| Solana DAS | | |
| Sui 对象/交易 | | |
| Sui 余额 | | |
| Sui 检查点流 | | |
One-file quickstart (copy/paste)
单文件快速入门(复制粘贴)
No API key? Use theskill instead. Replace API-key URLs withagentic-gatewayand addhttps://x402.alchemy.com/eth-mainnet/v2(orAuthorization: SIWE <token>for a Solana wallet). See theSIWS <token>skill for setup.agentic-gateway
没有 API Key? 改用Skill。将 API Key URL 替换为agentic-gateway,并添加https://x402.alchemy.com/eth-mainnet/v2(Solana 钱包使用Authorization: SIWE <token>)。有关设置,请参阅SIWS <token>Skill。agentic-gateway
EVM JSON-RPC (read)
EVM JSON-RPC(读取)
bash
curl -s https://eth-mainnet.g.alchemy.com/v2/$ALCHEMY_API_KEY \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}'bash
curl -s https://eth-mainnet.g.alchemy.com/v2/$ALCHEMY_API_KEY \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}'Create Notify webhook
创建 Notify Webhook
bash
curl -s -X POST "https://dashboard.alchemy.com/api/create-webhook" \
-H "Content-Type: application/json" \
-H "X-Alchemy-Token: $ALCHEMY_NOTIFY_AUTH_TOKEN" \
-d '{"network":"ETH_MAINNET","webhook_type":"ADDRESS_ACTIVITY","webhook_url":"https://example.com/webhook","addresses":["0x00000000219ab540356cbb839cbe05303d7705fa"]}'bash
curl -s -X POST "https://dashboard.alchemy.com/api/create-webhook" \
-H "Content-Type: application/json" \
-H "X-Alchemy-Token: $ALCHEMY_NOTIFY_AUTH_TOKEN" \
-d '{"network":"ETH_MAINNET","webhook_type":"ADDRESS_ACTIVITY","webhook_url":"https://example.com/webhook","addresses":["0x00000000219ab540356cbb839cbe05303d7705fa"]}'Verify webhook signature (Node)
验证 Webhook 签名(Node)
ts
import crypto from "crypto";
export function verify(rawBody: string, signature: string, secret: string) {
const hmac = crypto.createHmac("sha256", secret).update(rawBody).digest("hex");
return crypto.timingSafeEqual(Buffer.from(hmac), Buffer.from(signature));
}ts
import crypto from "crypto";
export function verify(rawBody: string, signature: string, secret: string) {
const hmac = crypto.createHmac("sha256", secret).update(rawBody).digest("hex");
return crypto.timingSafeEqual(Buffer.from(hmac), Buffer.from(signature));
}Network naming rules
网络命名规则
- JSON-RPC and most APIs use lowercase network enums like .
eth-mainnet - Notify API uses uppercase enums like .
ETH_MAINNET
- JSON-RPC 和大多数 API 使用小写网络枚举,例如 。
eth-mainnet - Notify API 使用大写枚举,例如 。
ETH_MAINNET
Common token addresses
常用代币地址
| Token | Chain | Address |
|---|---|---|
| ETH | ethereum | |
| WETH | ethereum | |
| USDC | ethereum | |
| USDC | base | |
| 代币 | 链 | 地址 |
|---|---|---|
| ETH | ethereum | |
| WETH | ethereum | |
| USDC | ethereum | |
| USDC | base | |
Failure modes + retries
失败模式与重试
- HTTP means rate limit. Use exponential backoff with jitter.
429 - JSON-RPC errors come in fields even with HTTP 200.
error - Use to resume pagination after failures.
pageKey - De-dupe websocket events on reconnect.
- HTTP 表示触发速率限制。使用带抖动的指数退避。
429 - 即使 HTTP 状态码为 200,JSON-RPC 错误也会出现在 字段中。
error - 失败后使用 恢复分页。
pageKey - 重连后对 WebSocket 事件去重。
Skill map
Skill 地图
For the complete reference index organized by product area, see .
references/skill-map.mdQuick category overview:
- Node: JSON-RPC, WebSocket, Debug, Trace, Enhanced APIs, Utility
- Webhooks: Address Activity, Custom (GraphQL), NFT Activity, Payloads, Signatures
- Solana: JSON-RPC, DAS, Yellowstone gRPC (streaming), Wallets
- Sui gRPC: Objects, Transactions, Balances, Move Packages, Name Service, Subscriptions, Signature Verification
- Wallets: Account Kit, Bundler, Gas Manager, Wallet APIs (formerly "Smart Wallets")
- Rollups: L2/L3 deployment overview
- Recipes: simulation, pending tx subscriptions, webhook flows
- Operational: Auth, Rate Limits, Best Practices
有关按产品领域组织的完整参考索引,请参阅 。
references/skill-map.md分类快速概览:
- Node:JSON-RPC、WebSocket、Debug、Trace、Enhanced APIs、Utility
- Webhooks:Address Activity、Custom (GraphQL)、NFT Activity、Payloads、Signatures
- Solana:JSON-RPC、DAS、Yellowstone gRPC(流式传输)、Wallets
- Sui gRPC:Objects、Transactions、Balances、Move Packages、Name Service、Subscriptions、Signature Verification
- Wallets:Account Kit、Bundler、Gas Manager、Wallet APIs(原名为 “Smart Wallets”)
- Rollups:L2/L3 部署概览
- Recipes:模拟交易、待处理交易订阅、Webhook 流程
- Operational:鉴权、速率限制、最佳实践
Handing off to other skills
转交给其他 Skill
| The user wants to... | Hand off to |
|---|---|
| Run a one-off live query, admin command, or on-machine automation in this session (CLI installed) | |
| Run a one-off live query in this session (only MCP wired in) | |
| Build app code without an API key (autonomous agent, or explicit x402/MPP) | |
| 用户希望…… | 转交给 |
|---|---|
| 在当前会话中运行一次性实时查询、管理命令或本机自动化(已安装 CLI) | |
| 在当前会话中运行一次性实时查询(仅接入 MCP) | |
| 构建无 API Key 的应用程序代码(自主 Agent,或明确要求使用 x402/MPP) | |
Troubleshooting
故障排除
API key not working
API Key 不生效
- Verify is set:
$ALCHEMY_API_KEYecho $ALCHEMY_API_KEY - Confirm the key is valid at dashboard.alchemy.com
- Check if allowlists restrict the key to specific IPs/domains (see )
references/operational-allowlists.md
- 验证 是否已设置:
$ALCHEMY_API_KEYecho $ALCHEMY_API_KEY - 确认 Key 在 dashboard.alchemy.com 中有效
- 检查 allowlist 是否将 Key 限制到特定 IP/域名(参阅 )
references/operational-allowlists.md
HTTP 429 (rate limited)
HTTP 429(触发速率限制)
- Use exponential backoff with jitter before retrying
- Check your compute unit budget in the Alchemy dashboard
- See for limits per plan
references/operational-rate-limits-and-compute-units.md
- 重试前使用带抖动的指数退避
- 在 Alchemy 控制台中检查计算单元额度
- 参阅 了解各套餐的限制
references/operational-rate-limits-and-compute-units.md
Wrong network slug
网络标识符错误
- JSON-RPC and most APIs use lowercase: ,
eth-mainnetbase-mainnet - Notify API uses uppercase: ,
ETH_MAINNETBASE_MAINNET - See for the full list
references/operational-supported-networks.md
- JSON-RPC 和大多数 API 使用小写格式:、
eth-mainnetbase-mainnet - Notify API 使用大写格式:、
ETH_MAINNETBASE_MAINNET - 完整列表参见
references/operational-supported-networks.md
JSON-RPC error with HTTP 200
HTTP 200 下的 JSON-RPC 错误
- Alchemy returns JSON-RPC errors inside the field even with a 200 status code
error - Always check in addition to HTTP status
response.error
- 即使状态码为 200,Alchemy 仍会在 字段中返回 JSON-RPC 错误
error - 除检查 HTTP 状态外,始终检查
response.error