CRITICAL: Read Rule Files Before Implementing
The #1 cause of bugs is using wrong HTTP methods or stream configurations.
For EVERY endpoint:
- 1. Read INLINECODE0
- 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:
- 1. This SKILL.md (core patterns)
- Endpoint rule file in INLINECODE1
- Pattern references in
references/ (for edge cases only)
Setup
API Key (optional)
Never ask the user to paste their API key into the chat. Instead:
- 1. Check if
MORALIS_API_KEY is set in the environment (try running [ -n "$MORALIS_API_KEY" ] && echo "API key is set" || echo "API key is NOT set"). - If not set, offer to create the
.env file with an empty placeholder: INLINECODE6 - Tell the user to open the
.env file and paste their key there themselves. - 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).
Environment Variable Discovery
The .env file location depends on how skills are installed:
Create the .env file in the project root (same directory the user runs Claude Code from). Make sure .env is in .gitignore.
Verify Your Key
CODEBLOCK0
Base URL
CODEBLOCK1
Important: Different from Data API (deep-index.moralis.io).
Authentication
All requests require: X-API-Key: $MORALIS_API_KEY
HTTP Methods (CRITICAL)
| Action | Method | Endpoint |
|---|
| Create stream | INLINECODE14 | INLINECODE15 |
| Update stream |
POST |
/streams/evm/{id} |
| Delete stream |
DELETE |
/streams/evm/{id} |
| Get streams |
GET |
/streams/evm |
| Replace addresses |
PATCH |
/streams/evm/{id}/address |
Common mistake: Using POST to create streams. Use PUT instead.
Stream Types
| Type | Description |
|---|
| INLINECODE24 | Native transactions |
| INLINECODE25 |
Contract event logs |
|
erc20transfer | ERC20 token transfers |
|
erc20approval | ERC20 approvals |
|
nfttransfer | NFT transfers |
|
internalTx | Internal transactions |
Quick Reference: Most Common Patterns
Stream ID Format (ALWAYS UUID)
CODEBLOCK2
Chain IDs (ALWAYS hex)
CODEBLOCK3
Event Signatures (topic0)
CODEBLOCK4
Status Values (lowercase only)
CODEBLOCK5
Common Pitfalls (Top 5)
- 1. Using POST to create streams - Use
PUT instead - Wrong base URL - Use
api.moralis-streams.com, NOT INLINECODE32 - 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.
Triggers (Read-Only Contract Calls)
Enrich webhook data with on-chain reads (e.g., balanceOf). Triggers execute view/pure functions and attach results to webhook events. Supports dynamic selectors ($contract, $from, $to). See references/Triggers.md for complete reference with examples.
Native Balances in Webhooks
Configure getNativeBalances to include native token balances (ETH, BNB, etc.) in webhook payloads. Requires Business plan+. See references/UsefulStreamOptions.md for configuration details.
Delivery and Error Handling
- - Two webhooks per event: Unconfirmed (
confirmed: false) + Confirmed (confirmed: true). Idempotent handlers required. - 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 Security
Webhooks are signed with your streams secret (different from API key).
- - Header: INLINECODE42
- Algorithm: INLINECODE43
CODEBLOCK6
See references/WebhookSecurity.md for complete examples.
Testing Endpoints
CODEBLOCK7
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
?limit=100 |
| "No webhooks" | Stream paused | Check status is "active" |
Endpoint Catalog
Complete list of all 20 Streams API endpoints organized by category.
Stream Management
Create, update, delete, and manage streams.
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 |
Status & Settings
Pause/resume streams and configure settings.
History & Analytics
Stream history, replay, statistics, logs, and block data.
Listen to All Addresses
Set allAddresses: true with a topic0 and abi 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.
Example: Create ERC20 Transfer Monitor
CODEBLOCK8
Pagination
List endpoints use cursor-based pagination:
CODEBLOCK9
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.
Reference Documentation
See Also
- - Endpoint rules:
rules/*.md files - Data API: @moralis-data-api for querying blockchain state
关键:实现前请先阅读规则文件
导致错误的头号原因是使用了错误的HTTP方法或流配置。
对于每个端点:
- 1. 读取 rules/{EndpointName}.md
- 检查HTTP方法(PUT用于创建,POST用于更新,DELETE用于删除)
- 验证流ID格式(UUID,而非十六进制)
- 使用十六进制链ID(0x1, 0x89),而非名称(eth, polygon)
阅读顺序:
- 1. 本SKILL.md(核心模式)
- rules/中的端点规则文件
- references/中的模式参考(仅用于边界情况)
设置
API密钥(可选)
切勿要求用户将API密钥粘贴到聊天中。 而是:
- 1. 检查环境中是否设置了MORALISAPIKEY(尝试运行[ -n $MORALISAPIKEY ] && echo API key is set || echo API key is NOT set)。
- 如果未设置,提供创建包含空占位符的.env文件:MORALISAPIKEY=
- 告诉用户打开.env文件并自行粘贴密钥。
- 告知用户:没有密钥,您将无法代表他们测试或调用Moralis API。
如果他们还没有密钥,请引导他们访问admin.moralis.com/register(免费,无需信用卡)。
环境变量发现
.env文件的位置取决于技能的安装方式:
在项目根目录(用户运行Claude Code的同一目录)创建.env文件。确保.env在.gitignore中。
验证您的密钥
bash
curl https://api.moralis-streams.com/streams/evm?limit=10 \
-H X-API-Key: $MORALISAPIKEY
基础URL
https://api.moralis-streams.com
重要提示: 与数据API(deep-index.moralis.io)不同。
认证
所有请求都需要:X-API-Key: $MORALISAPIKEY
HTTP方法(关键)
| 操作 | 方法 | 端点 |
|---|
| 创建流 | PUT | /streams/evm |
| 更新流 |
POST | /streams/evm/{id} |
| 删除流 | DELETE | /streams/evm/{id} |
| 获取流 | GET | /streams/evm |
| 替换地址 | PATCH | /streams/evm/{id}/address |
常见错误: 使用POST创建流。应使用PUT。
流类型
合约事件日志 |
| erc20transfer | ERC20代币转账 |
| erc20approval | ERC20授权 |
| nfttransfer | NFT转账 |
| internalTx | 内部交易 |
快速参考:最常见模式
流ID格式(始终为UUID)
typescript
// 错误 - 十六进制格式
0x1234567890abcdef
// 正确 - UUID格式
a1b2c3d4-e5f6-7890-abcd-ef1234567890
链ID(始终为十六进制)
typescript
0x1 // 以太坊
0x89 // Polygon
0x38 // BSC
0xa4b1 // Arbitrum
0xa // Optimism
0x2105 // Base
事件签名(topic0)
typescript
Transfer(address,address,uint256) // ERC20/NFT转账
Approval(address,address,uint256) // ERC20授权
状态值(仅小写)
typescript
active // 正确 - 正常运行状态
paused // 正确 - 手动暂停
error // 正确 - webhook成功率<70%时自动设置
terminated // 正确 - 不可恢复,处于error状态24小时后
ACTIVE // 错误
常见陷阱(前5个)
- 1. 使用POST创建流 - 应使用PUT
- 错误的基础URL - 使用api.moralis-streams.com,而非deep-index.moralis.io
- 十六进制流ID - 必须为UUID格式,而非十六进制
- 字符串链名称 - 使用十六进制(0x1),而非名称(eth)
- 大写状态 - 使用小写(active, paused)
- 测试webhook未返回200 - 除非您的端点在创建/更新期间发送的测试webhook返回2xx,否则流不会启动
完整参考请参见references/CommonPitfalls.md。
触发器(只读合约调用)
通过链上读取(例如balanceOf)丰富webhook数据。触发器执行view/pure函数并将结果附加到webhook事件。支持动态选择器($contract, $from, $to)。带有示例的完整参考请参见references/Triggers.md。
Webhook中的原生余额
配置getNativeBalances以在webhook负载中包含原生代币余额(ETH、BNB等)。需要Business计划及以上。配置详情请参见references/UsefulStreamOptions.md。
投递与错误处理
- - 每个事件两个webhook:未确认(confirmed: false)+ 已确认(confirmed: true)。需要幂等处理器。
- 流在错误状态持续24小时后自动终止(webhook成功率<70%)。这是不可恢复的——您必须创建新的流。
- 测试webhook:每次创建/更新时发送。必须返回200,否则流不会启动。
请参见references/DeliveryGuarantees.md和references/ErrorHandling.md。
Webhook安全
Webhook使用您的流密钥(与API密钥不同)签名。
- - 头部: 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。
测试端点
bash
WEBHOOK_URL=https://your-server.com/webhook
列出流(需要limit)
curl https://api.moralis-streams.com/streams/evm?limit=100 \
-H X-API-Key: $MORALIS
APIKEY
创建流(PUT,而非POST)
curl -X PUT https://api.moralis-streams.com/streams/evm \
-H X-API-Key: $MORALIS
APIKEY \
-H Content-Type: application/json \
-d {
webhookUrl: ${WEBHOOK_URL},
description: 测试流,
tag: test,
topic0: [Transfer(address,address,uint256)],
allAddresses: false,
chainIds: [0x1]
}
暂停流(POST到status)
curl -X POST https://api.moralis-streams.com/streams/evm/
/status \
-H X-API-Key: $MORALISAPIKEY \
-H Content-Type: application/json \
-d {status: paused}
快速故障排除
| 问题 | 原因 | 解决方案 |
|---|
| 400 Bad Request | 无效配置 | 检查webhookUrl、topic0格式、chainIds |
| 404 Not Found |
错误的流ID | 验证UUID格式 |
| Method Not Allowed | 错误的HTTP方法 | PUT用于创建,POST用于更新 |
| Missing limit | GET /streams/evm | 添加?limit=100 |
| No webhooks | 流已暂停 | 检查状态是否为active |
端点目录
按类别分类的所有20个Streams API端点的完整列表。
流管理
创建、更新、删除和管理流。
| 端点 |