moralis-streams-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCRITICAL: Read Rule Files Before Implementing
重要提示:实施前请阅读规则文件
The #1 cause of bugs is using wrong HTTP methods or stream configurations.
For EVERY endpoint:
- Read
rules/{EndpointName}.md - Check HTTP method (PUT for create, POST for update, DELETE for delete)
- Verify stream ID format (UUID, not hex)
- Use hex chain IDs (0x1, 0x89), not names (eth, polygon)
Reading Order:
- This SKILL.md (core patterns)
- Endpoint rule file in
rules/ - Pattern references in (for edge cases only)
references/
出现bug的首要原因是使用了错误的HTTP方法或流配置。
对于每个接口:
- 阅读 文件
rules/{EndpointName}.md - 确认HTTP方法(创建用PUT,更新用POST,删除用DELETE)
- 验证流ID格式(必须是UUID,不能是十六进制格式)
- 使用十六进制链ID(如0x1、0x89),而非链名称(如eth、polygon)
阅读顺序:
- 本SKILL.md文件(核心模式)
- 目录下的接口规则文件
rules/ - 目录下的模式参考(仅用于处理边缘情况)
references/
Setup
配置步骤
API Key (optional)
API Key(可选)
Never ask the user to paste their API key into the chat. Instead:
- Check if is set in the environment (try running
MORALIS_API_KEY).[ -n "$MORALIS_API_KEY" ] && echo "API key is set" || echo "API key is NOT set" - If not set, offer to create the file with an empty placeholder:
.envMORALIS_API_KEY= - Tell the user to open the file and paste their key there themselves.
.env - Let them know: without the key, you won't be able to test or call the Moralis API on their behalf.
If they don't have a key yet, point them to admin.moralis.com/register (free, no credit card).
切勿要求用户在聊天框中粘贴其API Key。 应按以下方式操作:
- 检查环境变量中是否已设置(可执行命令:
MORALIS_API_KEY)。[ -n "$MORALIS_API_KEY" ] && echo "API key is set" || echo "API key is NOT set" - 若未设置,提议创建包含空占位符的文件:
.envMORALIS_API_KEY= - 告知用户自行打开文件并粘贴其API Key。
.env - 说明:若无API Key,将无法代表用户测试或调用Moralis API。
若用户尚未拥有API Key,可引导其前往admin.moralis.com/register注册(免费,无需信用卡)。
Environment Variable Discovery
环境变量识别
The file location depends on how skills are installed:
.envCreate the file in the project root (same directory the user runs Claude Code from). Make sure is in .
.env.env.gitignore.env请在项目根目录(即用户运行Claude Code的目录)创建文件,并确保已添加到中。
.env.env.gitignoreVerify Your Key
验证API Key
bash
curl "https://api.moralis-streams.com/streams/evm?limit=10" \
-H "X-API-Key: $MORALIS_API_KEY"bash
curl "https://api.moralis-streams.com/streams/evm?limit=10" \
-H "X-API-Key: $MORALIS_API_KEY"Base URL
基础URL
https://api.moralis-streams.comImportant: Different from Data API ().
deep-index.moralis.iohttps://api.moralis-streams.com注意: 此URL与Data API的URL()不同。
deep-index.moralis.ioAuthentication
身份验证
All requests require:
X-API-Key: $MORALIS_API_KEY所有请求均需携带:
X-API-Key: $MORALIS_API_KEYHTTP Methods (CRITICAL)
HTTP方法(重点注意)
| Action | Method | Endpoint |
|---|---|---|
| Create stream | | |
| Update stream | | |
| Delete stream | | |
| Get streams | | |
| Replace addresses | | |
Common mistake: Using POST to create streams. Use PUT instead.
| 操作 | 方法 | 接口 |
|---|---|---|
| 创建流 | | |
| 更新流 | | |
| 删除流 | | |
| 获取流列表 | | |
| 替换流中地址 | | |
常见错误: 使用POST方法创建流。请改用PUT。
Stream Types
流类型
| Type | Description |
|---|---|
| Native transactions |
| Contract event logs |
| ERC20 token transfers |
| ERC20 approvals |
| NFT transfers |
| Internal transactions |
| 类型 | 描述 |
|---|---|
| 原生交易 |
| 合约事件日志 |
| ERC20代币转账 |
| ERC20授权 |
| NFT转账 |
| 内部交易 |
Quick Reference: Most Common Patterns
快速参考:最常用模式
Stream ID Format (ALWAYS UUID)
流ID格式(必须为UUID)
typescript
// WRONG - Hex format
"0x1234567890abcdef"
// CORRECT - UUID format
"YOUR_STREAM_ID"typescript
// 错误示例 - 十六进制格式
"0x1234567890abcdef"
// 正确示例 - UUID格式
"YOUR_STREAM_ID"Chain IDs (ALWAYS hex)
链ID(必须为十六进制)
typescript
"0x1" // Ethereum
"0x89" // Polygon
"0x38" // BSC
"0xa4b1" // Arbitrum
"0xa" // Optimism
"0x2105" // Basetypescript
"0x1" // Ethereum(以太坊)
"0x89" // Polygon(Polygon链)
"0x38" // BSC(币安智能链)
"0xa4b1" // Arbitrum(Arbitrum链)
"0xa" // Optimism(Optimism链)
"0x2105" // Base(Base链)Event Signatures (topic0)
事件签名(topic0)
typescript
"Transfer(address,address,uint256)" // ERC20/NFT Transfer
"Approval(address,address,uint256)" // ERC20 Approvaltypescript
"Transfer(address,address,uint256)" // ERC20/NFT转账事件
"Approval(address,address,uint256)" // ERC20授权事件Status Values (lowercase only)
状态值(仅支持小写)
typescript
"active" // CORRECT - normal operating state
"paused" // CORRECT - manually paused
"error" // CORRECT - auto-set when webhook success rate <70%
"terminated" // CORRECT - unrecoverable, after 24h in error
"ACTIVE" // WRONGtypescript
"active" // 正确 - 正常运行状态
"paused" // 正确 - 手动暂停
"error" // 正确 - 当Webhook成功率<70%时自动设置
"terminated" // 正确 - 错误状态持续24小时后进入,不可恢复
"ACTIVE" // 错误示例Common Pitfalls (Top 5)
常见陷阱(前5个)
- Using POST to create streams - Use instead
PUT - Wrong base URL - Use , NOT
api.moralis-streams.comdeep-index.moralis.io - Hex stream ID - Must be UUID format, not hex
- String chain names - Use hex (0x1), not names (eth)
- Uppercase status - Use lowercase ("active", "paused")
- Not returning 200 on test webhook - Stream won't start unless your endpoint returns 2xx on the test webhook sent during create/update
See references/CommonPitfalls.md for complete reference.
- 使用POST创建流 - 请改用方法
PUT - 使用错误的基础URL - 请使用,而非
api.moralis-streams.comdeep-index.moralis.io - 使用十六进制格式的流ID - 必须为UUID格式,不能是十六进制
- 使用字符串格式的链名称 - 请使用十六进制格式(如0x1),而非链名称(如eth)
- 使用大写状态值 - 请使用小写格式(如"active"、"paused")
- 测试Webhook未返回200状态码 - 创建/更新流时会发送测试Webhook,若未返回2xx状态码,流将无法启动
完整参考请见references/CommonPitfalls.md。
Triggers (Read-Only Contract Calls)
触发器(只读合约调用)
Enrich webhook data with on-chain reads (e.g., ). Triggers execute / functions and attach results to webhook events. Supports dynamic selectors (, , ). See references/Triggers.md for complete reference with examples.
balanceOfviewpure$contract$from$to通过链上只读调用(如)丰富Webhook数据。触发器可执行/函数,并将结果附加到Webhook事件中。支持动态选择器(如、、)。完整示例请见references/Triggers.md。
balanceOfviewpure$contract$from$toNative Balances in Webhooks
Webhook中的原生代币余额
Configure to include native token balances (ETH, BNB, etc.) in webhook payloads. Requires Business plan+. See references/UsefulStreamOptions.md for configuration details.
getNativeBalances配置可在Webhook payload中包含原生代币余额(如ETH、BNB等)。此功能需Business及以上套餐。配置详情请见references/UsefulStreamOptions.md。
getNativeBalancesDelivery and Error Handling
投递与错误处理
- Two webhooks per event: Unconfirmed () + Confirmed (
confirmed: false). Idempotent handlers required.confirmed: true - Streams auto-terminate after 24 hours in error state (webhook success rate <70%). This is unrecoverable — you must create a new stream.
- Test webhook: Sent on every create/update. Must return 200 or stream won't start.
See references/DeliveryGuarantees.md and references/ErrorHandling.md.
- 每个事件触发两次Webhook:未确认状态()+ 已确认状态(
confirmed: false)。需实现幂等处理逻辑。confirmed: true - 流在错误状态持续24小时后将自动终止(Webhook成功率<70%)。此状态不可恢复——必须创建新流。
- 测试Webhook:每次创建/更新流时都会发送。必须返回200状态码,否则流无法启动。
完整参考请见references/DeliveryGuarantees.md和references/ErrorHandling.md。
Webhook Security
Webhook安全
Webhooks are signed with your streams secret (different from API key).
- Header:
x-signature - Algorithm:
sha3(JSON.stringify(body) + secret)
javascript
const verifySignature = (req, secret) => {
const provided = req.headers["x-signature"];
const generated = web3.utils.sha3(JSON.stringify(req.body) + secret);
if (generated !== provided) throw new Error("Invalid Signature");
};See references/WebhookSecurity.md for complete examples.
Webhook会使用你的流密钥(与API Key不同)进行签名。
- 请求头:
x-signature - 算法:
sha3(JSON.stringify(body) + secret)
javascript
const verifySignature = (req, secret) => {
const provided = req.headers["x-signature"];
const generated = web3.utils.sha3(JSON.stringify(req.body) + secret);
if (generated !== provided) throw new Error("Invalid Signature");
};完整示例请见references/WebhookSecurity.md。
Testing Endpoints
测试接口
bash
WEBHOOK_URL="https://your-server.com/webhook"bash
WEBHOOK_URL="https://your-server.com/webhook"List streams (requires limit)
获取流列表(必须指定limit参数)
curl "https://api.moralis-streams.com/streams/evm?limit=100"
-H "X-API-Key: $MORALIS_API_KEY"
-H "X-API-Key: $MORALIS_API_KEY"
curl "https://api.moralis-streams.com/streams/evm?limit=100"
-H "X-API-Key: $MORALIS_API_KEY"
-H "X-API-Key: $MORALIS_API_KEY"
Create stream (PUT, not POST)
创建流(使用PUT,而非POST)
curl -X PUT "https://api.moralis-streams.com/streams/evm"
-H "X-API-Key: $MORALIS_API_KEY"
-H "Content-Type: application/json"
-d '{ "webhookUrl": "'${WEBHOOK_URL}'", "description": "Test stream", "tag": "test", "topic0": ["Transfer(address,address,uint256)"], "allAddresses": false, "chainIds": ["0x1"] }'
-H "X-API-Key: $MORALIS_API_KEY"
-H "Content-Type: application/json"
-d '{ "webhookUrl": "'${WEBHOOK_URL}'", "description": "Test stream", "tag": "test", "topic0": ["Transfer(address,address,uint256)"], "allAddresses": false, "chainIds": ["0x1"] }'
curl -X PUT "https://api.moralis-streams.com/streams/evm"
-H "X-API-Key: $MORALIS_API_KEY"
-H "Content-Type: application/json"
-d '{ "webhookUrl": "'${WEBHOOK_URL}'", "description": "Test stream", "tag": "test", "topic0": ["Transfer(address,address,uint256)"], "allAddresses": false, "chainIds": ["0x1"] }'
-H "X-API-Key: $MORALIS_API_KEY"
-H "Content-Type: application/json"
-d '{ "webhookUrl": "'${WEBHOOK_URL}'", "description": "Test stream", "tag": "test", "topic0": ["Transfer(address,address,uint256)"], "allAddresses": false, "chainIds": ["0x1"] }'
Pause stream (POST to status)
暂停流(通过POST修改状态)
curl -X POST "https://api.moralis-streams.com/streams/evm/<stream_id>/status"
-H "X-API-Key: $MORALIS_API_KEY"
-H "Content-Type: application/json"
-d '{"status": "paused"}'
-H "X-API-Key: $MORALIS_API_KEY"
-H "Content-Type: application/json"
-d '{"status": "paused"}'
---curl -X POST "https://api.moralis-streams.com/streams/evm/<stream_id>/status"
-H "X-API-Key: $MORALIS_API_KEY"
-H "Content-Type: application/json"
-d '{"status": "paused"}'
-H "X-API-Key: $MORALIS_API_KEY"
-H "Content-Type: application/json"
-d '{"status": "paused"}'
---Quick Troubleshooting
快速故障排查
| Issue | Cause | Solution |
|---|---|---|
| "400 Bad Request" | Invalid config | Check webhookUrl, topic0 format, chainIds |
| "404 Not Found" | Wrong stream ID | Verify UUID format |
| "Method Not Allowed" | Wrong HTTP method | PUT for create, POST for update |
| "Missing limit" | GET /streams/evm | Add |
| "No webhooks" | Stream paused | Check status is "active" |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| "400 Bad Request" | 配置无效 | 检查webhookUrl、topic0格式、chainIds是否正确 |
| "404 Not Found" | 流ID错误 | 验证流ID是否为UUID格式 |
| "Method Not Allowed" | HTTP方法错误 | 创建用PUT,更新用POST |
| "Missing limit" | 调用GET /streams/evm时未传参数 | 添加 |
| "No webhooks" | 流已暂停 | 检查流状态是否为"active" |
Endpoint Catalog
接口目录
Complete list of all 20 Streams API endpoints organized by category.
按类别整理的全部20个Streams API接口。
Stream Management
流管理
Create, update, delete, and manage streams.
| Endpoint | Description |
|---|---|
| AddAddressToStream | Add address to stream |
| CreateStream | Create stream |
| DeleteAddressFromStream | Delete address from stream |
| DeleteStream | Delete stream |
| DuplicateStream | Duplicate stream |
| GetAddresses | Get addresses by stream |
| GetHistory | Get history |
| GetLogs | Get logs |
| GetSettings | Get project settings |
| GetStats | Get project stats |
| GetStatsByStreamId | Get project stats by Stream ID |
| GetStream | Get a specific evm stream. |
| GetStreamBlockDataByNumber | Get webhook data returned on the block number with provided stream config |
| GetStreamBlockDataToWebhookByNumber | Send webhook based on a specific block number using stream config and addresses. |
| GetStreams | Get streams |
| ReplaceAddressFromStream | Replaces address from stream |
| UpdateStream | Update stream |
| UpdateStreamStatus | Update stream status |
创建、更新、删除及管理流。
| 接口 | 描述 |
|---|---|
| AddAddressToStream | 向流中添加地址 |
| CreateStream | 创建流 |
| DeleteAddressFromStream | 从流中移除地址 |
| DeleteStream | 删除流 |
| DuplicateStream | 复制流 |
| GetAddresses | 获取流关联的地址列表 |
| GetHistory | 获取历史记录 |
| GetLogs | 获取日志 |
| GetSettings | 获取项目设置 |
| GetStats | 获取项目统计数据 |
| GetStatsByStreamId | 按流ID获取项目统计数据 |
| GetStream | 获取指定EVM流的详情 |
| GetStreamBlockDataByNumber | 根据区块号获取流配置对应的Webhook数据 |
| GetStreamBlockDataToWebhookByNumber | 根据指定区块号、流配置和地址发送Webhook |
| GetStreams | 获取流列表 |
| ReplaceAddressFromStream | 替换流中的地址 |
| UpdateStream | 更新流 |
| UpdateStreamStatus | 更新流状态 |
Status & Settings
状态与设置
Pause/resume streams and configure settings.
| Endpoint | Description |
|---|---|
| SetSettings | Set project settings |
暂停/恢复流及配置项目设置。
| 接口 | 描述 |
|---|---|
| SetSettings | 设置项目配置 |
History & Analytics
历史与分析
Stream history, replay, statistics, logs, and block data.
| Endpoint | Description |
|---|---|
| ReplayHistory | Replay history |
流历史、重放、统计、日志及区块数据。
| 接口 | 描述 |
|---|---|
| ReplayHistory | 重放历史事件 |
Listen to All Addresses
监听链上所有地址
Set with a and to monitor an event across every contract on a chain (e.g., all ERC20 transfers network-wide). Requires higher-tier plans. See references/ListenToAllAddresses.md for complete examples, ABI templates, and gotchas.
allAddresses: truetopic0abi设置并指定和,即可监控链上所有合约的指定事件(如全网所有ERC20转账)。此功能需高级套餐支持。完整示例、ABI模板及注意事项请见references/ListenToAllAddresses.md。
allAddresses: truetopic0abiExample: Create ERC20 Transfer Monitor
示例:创建ERC20转账监控流
bash
curl -X PUT "https://api.moralis-streams.com/streams/evm" \
-H "X-API-Key: $MORALIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"webhookUrl": "https://your-server.com/webhook",
"description": "Monitor ERC20 transfers",
"tag": "erc20-monitor",
"topic0": ["Transfer(address,address,uint256)"],
"allAddresses": true,
"chainIds": ["0x1", "0x89"],
"advancedOptions": [{
"topic0": "Transfer(address,address,uint256)",
"includeNativeHash": true
}]
}'bash
curl -X PUT "https://api.moralis-streams.com/streams/evm" \
-H "X-API-Key: $MORALIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"webhookUrl": "https://your-server.com/webhook",
"description": "Monitor ERC20 transfers",
"tag": "erc20-monitor",
"topic0": ["Transfer(address,address,uint256)"],
"allAddresses": true,
"chainIds": ["0x1", "0x89"],
"advancedOptions": [{
"topic0": "Transfer(address,address,uint256)",
"includeNativeHash": true
}]
}'Pagination
分页
List endpoints use cursor-based pagination:
bash
undefined列表类接口使用基于游标(cursor)的分页:
bash
undefinedFirst page
第一页
curl "...?limit=100" -H "X-API-Key: $KEY"
curl "...?limit=100" -H "X-API-Key: $KEY"
Next page
下一页
curl "...?limit=100&cursor=<cursor>" -H "X-API-Key: $KEY"
---curl "...?limit=100&cursor=<cursor>" -H "X-API-Key: $KEY"
---Supported Chains
支持的链
All major EVM chains: Ethereum (0x1), Polygon (0x89), BSC (0x38), Arbitrum (0xa4b1), Optimism (0xa), Base (0x2105), Avalanche (0xa86a), and more.
See references/StreamConfiguration.md for complete chain ID list.
所有主流EVM兼容链:Ethereum(0x1)、Polygon(0x89)、BSC(0x38)、Arbitrum(0xa4b1)、Optimism(0xa)、Base(0x2105)、Avalanche(0xa86a)等。
完整链ID列表请见references/StreamConfiguration.md。
Reference Documentation
参考文档
- references/CommonPitfalls.md - Complete pitfalls reference
- references/DeliveryGuarantees.md - At-least-once delivery, dual webhooks, confirmation blocks, test webhooks
- references/ErrorHandling.md - Retry schedule, error/terminated states, rate limits, re-org handling
- references/FAQ.md - Streams API frequently asked questions
- references/FilterStreams.md - Webhook data filtering to reduce noise
- references/ListenToAllAddresses.md - Monitor events across all contracts on a chain
- references/MonitorMultipleAddresses.md - Multi-address monitoring patterns
- references/ReplayFailedWebhooks.md - Replay failed webhook guide
- references/StreamConfiguration.md - Stream config reference
- references/Triggers.md - Read-only contract call enrichment (balanceOf, etc.)
- references/Tutorials.md - Real-world examples and tutorials
- references/UsefulStreamOptions.md - Advanced stream configuration options
- references/WebhookResponseBody.md - Webhook payload structure
- references/WebhookSecurity.md - Signature verification
- references/CommonPitfalls.md - 常见陷阱完整参考
- references/DeliveryGuarantees.md - 至少一次投递、双重Webhook、确认区块、测试Webhook
- references/ErrorHandling.md - 重试机制、错误/终止状态、速率限制、链重组处理
- references/FAQ.md - Streams API常见问题
- references/FilterStreams.md - Webhook数据过滤以减少冗余
- references/ListenToAllAddresses.md - 监控链上所有合约的事件
- references/MonitorMultipleAddresses.md - 多地址监控模式
- references/ReplayFailedWebhooks.md - 重放失败Webhook指南
- references/StreamConfiguration.md - 流配置参考
- references/Triggers.md - 只读合约调用数据增强(如balanceOf等)
- references/Tutorials.md - 实战示例与教程
- references/UsefulStreamOptions.md - 高级流配置选项
- references/WebhookResponseBody.md - Webhook payload结构
- references/WebhookSecurity.md - 签名验证
See Also
另请参阅
- Endpoint rules: files
rules/*.md - Data API: @moralis-data-api for querying blockchain state
- 接口规则:文件
rules/*.md - Data API:@moralis-data-api(用于查询区块链状态)