alchemy-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Alchemy CLI

Alchemy CLI

The Alchemy CLI (
@alchemy/cli
) is installed. Use it for all Alchemy API interactions instead of curl or raw HTTP.
已安装Alchemy CLI
@alchemy/cli
)。请使用它完成所有Alchemy API交互,替代curl或原生HTTP请求。

Install

安装

bash
npm i -g @alchemy/cli
bash
npm i -g @alchemy/cli

Bootstrap

初始化引导

Run this at the start of any session to get the full command contract (every command, flag, auth method, error code, and example):
bash
alchemy --json --no-interactive agent-prompt
在任何会话开始时运行以下命令,获取完整的命令约定(包含所有命令、标志、身份验证方法、错误代码及示例):
bash
alchemy --json --no-interactive agent-prompt

Execution Rules

执行规则

  • ALWAYS pass
    --json --no-interactive
    on every command
  • Parse stdout as JSON on exit code 0
  • Parse stderr as JSON on nonzero exit code
  • NEVER run bare
    alchemy
    without
    --json --no-interactive
  • NEVER use curl or raw HTTP when an
    alchemy
    CLI command exists for the task
  • 所有命令必须携带
    --json --no-interactive
    参数
  • 退出码为0时,将标准输出解析为JSON格式
  • 退出码非0时,将标准错误输出解析为JSON格式
  • 绝对不要在不携带
    --json --no-interactive
    参数的情况下运行
    alchemy
    命令
  • 当已有对应的
    alchemy
    CLI命令时,绝对不要使用curl或原生HTTP请求完成任务

Preflight

预检步骤

Before the first command, check auth readiness:
bash
alchemy --json --no-interactive setup status
If
complete
is false, follow the
nextCommands
in the response to configure auth.
首次执行命令前,检查身份验证就绪状态:
bash
alchemy --json --no-interactive setup status
如果
complete
为false,请按照响应中的
nextCommands
配置身份验证。

Auth Setup

身份验证设置

The fastest way to authenticate is via browser login:
bash
alchemy auth login
This opens a browser to authenticate with your Alchemy account and automatically configures the CLI with your credentials.
To check auth status:
alchemy auth status
To log out:
alchemy auth logout
最快的身份验证方式是通过浏览器登录:
bash
alchemy auth login
此命令会打开浏览器,使用你的Alchemy账号完成身份验证,并自动为CLI配置凭据。
查看身份验证状态:
alchemy auth status
退出登录:
alchemy auth logout

Alternative auth methods

备选身份验证方式

MethodConfig commandEnv varUsed by
Browser login
alchemy auth login
--All commands (provides both API key and access key)
API key
alchemy config set api-key <key>
ALCHEMY_API_KEY
balance, tx, block, rpc, tokens, nfts, transfers, prices, portfolio, simulate, solana
Access key
alchemy config set access-key <key>
ALCHEMY_ACCESS_KEY
apps, network list
Webhook key
alchemy config set webhook-api-key <key>
ALCHEMY_WEBHOOK_API_KEY
webhooks
x402 wallet
alchemy wallet generate
then
alchemy config set x402 true
ALCHEMY_WALLET_KEY
balance, tx, block, rpc, tokens, nfts, transfers
Get API/access keys at dashboard.alchemy.com.
方式配置命令环境变量适用命令
浏览器登录
alchemy auth login
--所有命令(同时提供API密钥和访问密钥)
API密钥
alchemy config set api-key <key>
ALCHEMY_API_KEY
balance, tx, block, rpc, tokens, nfts, transfers, prices, portfolio, simulate, solana
访问密钥
alchemy config set access-key <key>
ALCHEMY_ACCESS_KEY
apps, network list
Webhook密钥
alchemy config set webhook-api-key <key>
ALCHEMY_WEBHOOK_API_KEY
webhooks
x402钱包
alchemy wallet generate
然后执行
alchemy config set x402 true
ALCHEMY_WALLET_KEY
balance, tx, block, rpc, tokens, nfts, transfers
dashboard.alchemy.com获取API/访问密钥。

Task-to-Command Map

任务-命令映射表

Node (EVM)

节点(EVM)

TaskCommand
ETH balance
alchemy balance <address>
Transaction details
alchemy tx <hash>
Transaction receipt
alchemy receipt <hash>
Block details
alchemy block <number|latest>
Gas prices
alchemy gas
Event logs
alchemy logs --address <addr> --from-block <n> --to-block <n>
Raw JSON-RPC
alchemy rpc <method> [params...]
Trace methods
alchemy trace <method> [params...]
Debug methods
alchemy debug <method> [params...]
任务命令
ETH余额
alchemy balance <address>
交易详情
alchemy tx <hash>
交易收据
alchemy receipt <hash>
区块详情
alchemy block <number|latest>
燃气价格
alchemy gas
事件日志
alchemy logs --address <addr> --from-block <n> --to-block <n>
原生JSON-RPC
alchemy rpc <method> [params...]
追踪方法
alchemy trace <method> [params...]
调试方法
alchemy debug <method> [params...]

Data

数据操作

TaskCommand
ERC-20 balances
alchemy tokens balances <address>
ERC-20 balances (formatted)
alchemy tokens balances <address> --metadata
Token metadata
alchemy tokens metadata <contract>
Token allowance
alchemy tokens allowance --owner <addr> --spender <addr> --contract <addr>
List owned NFTs
alchemy nfts <address>
NFT metadata
alchemy nfts metadata --contract <addr> --token-id <id>
NFT contract metadata
alchemy nfts contract <address>
Transfer history
alchemy transfers <address> --category erc20,erc721
Spot prices by symbol
alchemy prices symbol ETH,USDC
Spot prices by address
alchemy prices address --addresses '<json>'
Historical prices
alchemy prices historical --body '<json>'
Token portfolio
alchemy portfolio tokens --body '<json>'
NFT portfolio
alchemy portfolio nfts --body '<json>'
Portfolio transactions
alchemy portfolio transactions --body '<json>'
Simulate asset changes
alchemy simulate asset-changes --tx '<json>'
Simulate execution
alchemy simulate execution --tx '<json>'
任务命令
ERC-20余额
alchemy tokens balances <address>
ERC-20余额(格式化)
alchemy tokens balances <address> --metadata
代币元数据
alchemy tokens metadata <contract>
代币授权额度
alchemy tokens allowance --owner <addr> --spender <addr> --contract <addr>
列出持有的NFT
alchemy nfts <address>
NFT元数据
alchemy nfts metadata --contract <addr> --token-id <id>
NFT合约元数据
alchemy nfts contract <address>
转账历史
alchemy transfers <address> --category erc20,erc721
按符号查询现货价格
alchemy prices symbol ETH,USDC
按地址查询现货价格
alchemy prices address --addresses '<json>'
历史价格
alchemy prices historical --body '<json>'
代币投资组合
alchemy portfolio tokens --body '<json>'
NFT投资组合
alchemy portfolio nfts --body '<json>'
投资组合交易记录
alchemy portfolio transactions --body '<json>'
模拟资产变化
alchemy simulate asset-changes --tx '<json>'
模拟执行
alchemy simulate execution --tx '<json>'

Solana

Solana

TaskCommand
Solana JSON-RPC
alchemy solana rpc <method> [params...]
Solana DAS (NFTs/assets)
alchemy solana das <method> '<json>'
任务命令
Solana JSON-RPC
alchemy solana rpc <method> [params...]
Solana DAS(NFT/资产)
alchemy solana das <method> '<json>'

Webhooks

Webhook管理

TaskCommand
List webhooks
alchemy webhooks list
Create webhook
alchemy webhooks create --body '<json>'
Update webhook
alchemy webhooks update --body '<json>'
Delete webhook
alchemy webhooks delete <id>
任务命令
列出Webhook
alchemy webhooks list
创建Webhook
alchemy webhooks create --body '<json>'
更新Webhook
alchemy webhooks update --body '<json>'
删除Webhook
alchemy webhooks delete <id>

App Management

应用管理

TaskCommand
List apps
alchemy apps list
Create app
alchemy apps create --name "My App" --networks eth-mainnet
Update app
alchemy apps update <id> --name "New Name"
Delete app
alchemy apps delete <id>
List networks
alchemy network list
任务命令
列出应用
alchemy apps list
创建应用
alchemy apps create --name "My App" --networks eth-mainnet
更新应用
alchemy apps update <id> --name "New Name"
删除应用
alchemy apps delete <id>
列出网络
alchemy network list

CLI Admin

CLI管理

TaskCommand
Check for CLI updates
alchemy update-check
View config
alchemy config list
Reset config
alchemy config reset --yes
CLI version
alchemy version
任务命令
检查CLI更新
alchemy update-check
查看配置
alchemy config list
重置配置
alchemy config reset --yes
CLI版本
alchemy version

Global Flags

全局标志

FlagDescription
--json
Force JSON output
--no-interactive
Disable prompts and REPL
-n, --network <network>
Target network (default:
eth-mainnet
)
--api-key <key>
Override API key per command
--access-key <key>
Override access key per command
--x402
Use x402 wallet auth for this command
--timeout <ms>
Request timeout in milliseconds
-q, --quiet
Suppress non-essential output
--verbose
Log request/response details to stderr
标志描述
--json
强制输出JSON格式
--no-interactive
禁用提示和REPL
-n, --network <network>
目标网络(默认:
eth-mainnet
--api-key <key>
按命令覆盖API密钥
--access-key <key>
按命令覆盖访问密钥
--x402
为此命令使用x402钱包身份验证
--timeout <ms>
请求超时时间(毫秒)
-q, --quiet
抑制非必要输出
--verbose
将请求/响应详情记录到标准错误输出

Error Handling

错误处理

Errors return structured JSON on stderr. Key error codes:
CodeRetryableRecovery
AUTH_REQUIRED
NoSet
ALCHEMY_API_KEY
or run
alchemy config set api-key <key>
RATE_LIMITED
YesWait and retry with backoff
PAYMENT_REQUIRED
NoFund x402 wallet or switch to API key auth
RPC_ERROR
NoCheck method, params, and network
NETWORK_ERROR
YesCheck connection and retry
SETUP_REQUIRED
NoRun
alchemy --json setup status
and follow
nextCommands
For the full error code list, see
agent-prompt
output.
错误会在标准错误输出返回结构化JSON。关键错误代码:
代码是否可重试恢复方案
AUTH_REQUIRED
设置
ALCHEMY_API_KEY
或执行
alchemy config set api-key <key>
RATE_LIMITED
等待后重试并使用退避策略
PAYMENT_REQUIRED
为x402钱包充值或切换为API密钥身份验证
RPC_ERROR
检查方法、参数及网络
NETWORK_ERROR
检查连接后重试
SETUP_REQUIRED
执行
alchemy --json setup status
并遵循
nextCommands
完整错误代码列表请查看
agent-prompt
输出。

Official Links

官方链接