Skip to content

Commit 98754a7

Browse files
huth-stacksclaude
andcommitted
Add Chainhooks, Signer Metrics, and Token Metadata API reference sections
Faithfully migrates 3 Hiro API reference sections with complete content preservation. Each section includes overview, usage guide, and prominent links to the full OpenAPI-powered interactive reference on Hiro docs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 386a20a commit 98754a7

10 files changed

Lines changed: 555 additions & 2 deletions

File tree

docs/build/get-started/create-a-token/fungible-tokens.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ If you plan on updating your token's metadata in the future, you should definite
240240
;; ...
241241
```
242242

243-
Hiro’s [Token Metadata API](https://www.hiro.so/token-metadata-api) watches for that specific print event (specifically the notification of "token-metadata-update") on the network and auto-updates the API’s database to reflect a change in the existing token’s metadata.
243+
Hiro’s [Token Metadata API](../../../reference/api/token-metadata-api/) watches for that specific print event (specifically the notification of "token-metadata-update") on the network and auto-updates the API’s database to reflect a change in the existing token’s metadata.
244244

245245
If your token contract did not implement this print event, you could use the helper contract below to invoke a function that'll emit the same print event notification. Just invoke the `ft-metadata-update-notify` function of this contract below:
246246

docs/build/get-started/create-a-token/non-fungible-tokens.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ If you plan on updating your NFT's metadata in the future, you should definitely
186186
;; ...
187187
</code></pre>
188188

189-
Hiro’s [Token Metadata API](https://www.hiro.so/token-metadata-api) watches for that specific print event (specifically the notification of "token-metadata-update") on the network and auto-updates the API’s database to reflect a change in the existing NFT’s metadata.
189+
Hiro’s [Token Metadata API](../../../reference/api/token-metadata-api/) watches for that specific print event (specifically the notification of "token-metadata-update") on the network and auto-updates the API’s database to reflect a change in the existing NFT’s metadata.
190190

191191
If your NFT contract did not implement this print event, you could use the helper contract below to invoke a function that'll emit the same print event notification. Just invoke the `nft-metadata-update-notify` function of this contract below:
192192

docs/operate/run-a-signer/how-to-monitor-signer.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# How to Monitor Signer
22

3+
{% hint style="info" %}
4+
For programmatic monitoring of signer behavior, block acceptance rates, and PoX cycle metrics via REST API, see the [Signer Metrics API reference](../../reference/api/signer-metrics-api/).
5+
{% endhint %}
6+
37
We will use [Grafana Cloud](https://grafana.com/) to observe and monitor both the Signer and its corresponding Stacks node.
48

59
## Requirements

docs/reference/SUMMARY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
kind: openapi
7070
spec: sbtc-emily-api
7171
```
72+
* [Chainhooks API](api/chainhooks-api/README.md)
73+
* [Usage](api/chainhooks-api/usage.md)
74+
* [Signer Metrics API](api/signer-metrics-api/README.md)
75+
* [Usage](api/signer-metrics-api/usage.md)
76+
* [Token Metadata API](api/token-metadata-api/README.md)
77+
* [Usage](api/token-metadata-api/usage.md)
7278
7379
## Clarity
7480
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Chainhooks API
2+
3+
REST API for managing Chainhooks programmatically.
4+
5+
{% hint style="info" %}
6+
This page is migrated from the [Hiro documentation](https://docs.hiro.so/en/apis/chainhooks-api).
7+
{% endhint %}
8+
9+
## Overview
10+
11+
The Chainhooks API is a REST API that allows you to programmatically manage chainhooks, configure event filters, and control webhook delivery. It provides the same functionality covered in the [Chainhooks SDK introduction](https://docs.hiro.so/en/tools/chainhooks/introduction) through direct HTTP requests.
12+
13+
## Key Features
14+
15+
- **Full chainhook management** - Create, read, update, and delete chainhooks
16+
- **Webhook configuration** - Set up HTTP POST endpoints for event delivery
17+
- **Evaluation endpoints** - Test chainhooks against historical blocks
18+
19+
## Base URLs
20+
21+
The Chainhooks API is available on both mainnet and testnet:
22+
23+
```
24+
Testnet: https://api.testnet.hiro.so/chainhooks/v1
25+
Mainnet: https://api.mainnet.hiro.so/chainhooks/v1
26+
```
27+
28+
## API Reference
29+
30+
{% hint style="info" %}
31+
For the complete interactive API reference with all endpoints, request/response schemas, and try-it-out functionality, see the [Chainhooks API Reference on Hiro Docs](https://docs.hiro.so/en/apis/chainhooks-api/reference/chainhooks).
32+
{% endhint %}
33+
34+
### Available Endpoints
35+
36+
| Endpoint | Description |
37+
|----------|-------------|
38+
| Register chainhook | Create a new chainhook with event filters and webhook delivery |
39+
| Get all chainhooks | List all registered chainhooks |
40+
| Get one chainhook | Retrieve a specific chainhook by UUID |
41+
| Update chainhook | Modify an existing chainhook configuration |
42+
| Delete chainhook | Remove a registered chainhook |
43+
| Evaluate chainhook | Test a chainhook against historical blocks |
44+
| Enable chainhook | Enable a specific chainhook |
45+
| Disable chainhook | Disable a specific chainhook |
46+
| Bulk enable/disable | Enable or disable multiple chainhooks matching filters |
47+
| Get status | Retrieve the current status of a chainhook |
48+
| Rotate secret | Rotate the consumer secret for webhook security |
49+
| Delete secret | Remove the consumer secret |
50+
51+
## Next Steps
52+
53+
- [Usage Guide](usage.md): Authentication and best practices
54+
- [API Reference](https://docs.hiro.so/en/apis/chainhooks-api/reference/chainhooks): Complete endpoint documentation
55+
56+
{% hint style="info" %}
57+
### Need help building with the Chainhooks API?
58+
Reach out to us on the **#chainhook** channel on [Discord](https://stacks.chat/) under Hiro Developer Tools. There's also a [weekly office hours](https://www.addevent.com/event/oL21905919) call every Thursday at 11am ET.
59+
{% endhint %}
Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
# Usage
2+
3+
Learn how to authenticate, make requests, and handle responses with the Chainhooks API.
4+
5+
{% hint style="info" %}
6+
This page is migrated from the [Hiro documentation](https://docs.hiro.so/en/apis/chainhooks-api/usage).
7+
{% endhint %}
8+
9+
## Authentication
10+
11+
All Chainhooks API requests require authentication using a Hiro API key.
12+
13+
### Get Your API Key
14+
15+
1. Visit [platform.hiro.so](https://platform.hiro.so)
16+
2. Sign in or create an account
17+
3. Navigate to API Keys
18+
4. Generate or copy your API key
19+
20+
### Using Your API Key
21+
22+
Include your API key in the `x-api-key` header for all requests:
23+
24+
```bash
25+
curl https://api.testnet.hiro.so/chainhooks/v1/me/ \
26+
-H "x-api-key: YOUR_API_KEY"
27+
```
28+
29+
**Security best practices:**
30+
- Store API keys in environment variables, never in code
31+
- Use different keys for development and production
32+
- Rotate keys periodically
33+
- Never commit keys to version control
34+
35+
## Base URLs
36+
37+
Use the appropriate base URL for your environment:
38+
39+
```
40+
Testnet: https://api.testnet.hiro.so/chainhooks/v1
41+
Mainnet: https://api.mainnet.hiro.so/chainhooks/v1
42+
```
43+
44+
**Always test on testnet first** before deploying to mainnet.
45+
46+
## Request Format
47+
48+
### Headers
49+
50+
All requests should include:
51+
52+
```http
53+
Content-Type: application/json
54+
x-api-key: YOUR_API_KEY
55+
```
56+
57+
### Request Body
58+
59+
Most endpoints accept JSON request bodies. Example for registering a chainhook:
60+
61+
```bash
62+
curl -X POST https://api.testnet.hiro.so/chainhooks/v1/me/ \
63+
-H "x-api-key: YOUR_API_KEY" \
64+
-H "Content-Type: application/json" \
65+
-d '{
66+
"name": "my-chainhook",
67+
"version": "1",
68+
"chain": "stacks",
69+
"network": "testnet",
70+
"filters": {
71+
"events": [{
72+
"type": "stx_transfer",
73+
"sender": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM"
74+
}]
75+
},
76+
"action": {
77+
"type": "http_post",
78+
"url": "https://example.com/webhooks"
79+
}
80+
}'
81+
```
82+
83+
## Response Format
84+
85+
### Success Responses
86+
87+
Successful responses return JSON with relevant data:
88+
89+
```json
90+
{
91+
"uuid": "123e4567-e89b-12d3-a456-426614174000",
92+
"definition": {
93+
"name": "my-chainhook",
94+
"version": "1",
95+
"chain": "stacks",
96+
"network": "testnet",
97+
...
98+
},
99+
"status": {
100+
"status": "new",
101+
"enabled": false,
102+
"created_at": 1234567890,
103+
...
104+
}
105+
}
106+
```
107+
108+
### HTTP Status Codes
109+
110+
| Code | Meaning | Description |
111+
|------|---------|-------------|
112+
| 200 | OK | Request succeeded, response body contains data |
113+
| 204 | No Content | Request succeeded, no response body |
114+
| 400 | Bad Request | Invalid request format or parameters |
115+
| 401 | Unauthorized | Missing or invalid API key |
116+
| 404 | Not Found | Chainhook UUID not found |
117+
| 429 | Too Many Requests | Rate limit exceeded |
118+
| 500 | Server Error | Internal server error |
119+
120+
### Error Responses
121+
122+
Error responses include details about what went wrong:
123+
124+
```json
125+
{
126+
"error": "Invalid request body",
127+
"details": "filters.events is required"
128+
}
129+
```
130+
131+
## Common Patterns
132+
133+
### List All Chainhooks
134+
135+
```bash
136+
curl https://api.testnet.hiro.so/chainhooks/v1/me/ \
137+
-H "x-api-key: YOUR_API_KEY"
138+
```
139+
140+
### Get a chainhook
141+
142+
```bash
143+
curl https://api.testnet.hiro.so/chainhooks/v1/me/{uuid} \
144+
-H "x-api-key: YOUR_API_KEY"
145+
```
146+
147+
### Enable a Chainhook
148+
149+
```bash
150+
curl -X PATCH https://api.testnet.hiro.so/chainhooks/v1/me/{uuid}/enabled \
151+
-H "x-api-key: YOUR_API_KEY" \
152+
-H "Content-Type: application/json" \
153+
-d '{"enabled": true}'
154+
```
155+
156+
### Delete a Chainhook
157+
158+
```bash
159+
curl -X DELETE https://api.testnet.hiro.so/chainhooks/v1/me/{uuid} \
160+
-H "x-api-key: YOUR_API_KEY"
161+
```
162+
163+
### Evaluate Against a Block
164+
165+
Test your chainhook against a specific block:
166+
167+
```bash
168+
curl -X POST https://api.testnet.hiro.so/chainhooks/v1/me/{uuid}/evaluate \
169+
-H "x-api-key: YOUR_API_KEY" \
170+
-H "Content-Type: application/json" \
171+
-d '{"block_height": 150000}'
172+
```
173+
174+
### Bulk Enable/Disable
175+
176+
Enable or disable multiple chainhooks matching filters:
177+
178+
```bash
179+
curl -X PATCH https://api.testnet.hiro.so/chainhooks/v1/me/enabled \
180+
-H "x-api-key: YOUR_API_KEY" \
181+
-H "Content-Type: application/json" \
182+
-d '{
183+
"enabled": false,
184+
"filters": {
185+
"webhook_url": "https://old-endpoint.com/webhooks"
186+
}
187+
}'
188+
```
189+
190+
## Rate Limits
191+
192+
The Chainhooks API enforces rate limits based on your subscription tier:
193+
194+
- Free tier: 100 requests per minute
195+
- Pro tier: 1000 requests per minute
196+
- Enterprise: Custom limits
197+
198+
When rate limited, you'll receive a `429 Too Many Requests` response. Implement exponential backoff in your application:
199+
200+
```javascript
201+
async function makeRequestWithRetry(url, options, maxRetries = 3) {
202+
for (let i = 0; i < maxRetries; i++) {
203+
const response = await fetch(url, options);
204+
205+
if (response.status === 429) {
206+
const delay = Math.pow(2, i) * 1000;
207+
await new Promise(resolve => setTimeout(resolve, delay));
208+
continue;
209+
}
210+
211+
return response;
212+
}
213+
214+
throw new Error('Max retries exceeded');
215+
}
216+
```
217+
218+
## Webhook Security
219+
220+
### Consumer Secret
221+
222+
When you register a chainhook, webhook payloads include an `x-chainhook-consumer-secret` header. Validate this secret in your webhook endpoint:
223+
224+
```javascript
225+
app.post('/webhooks', (req, res) => {
226+
const receivedSecret = req.headers['x-chainhook-consumer-secret'];
227+
const expectedSecret = process.env.CHAINHOOK_CONSUMER_SECRET;
228+
229+
if (receivedSecret !== expectedSecret) {
230+
return res.status(401).send('Unauthorized');
231+
}
232+
233+
// Process webhook payload
234+
res.sendStatus(200);
235+
});
236+
```
237+
238+
### Rotate Secret
239+
240+
Periodically rotate your consumer secret:
241+
242+
```bash
243+
curl -X POST https://api.testnet.hiro.so/chainhooks/v1/me/secret \
244+
-H "x-api-key: YOUR_API_KEY"
245+
```
246+
247+
Store the new secret securely and update your webhook endpoint.
248+
249+
## Best Practices
250+
251+
1. **Start on testnet** - Always test chainhooks on testnet before mainnet
252+
2. **Enable gradually** - Create chainhooks disabled, test with `evaluate`, then enable
253+
3. **Handle errors** - Implement proper error handling and retries
254+
4. **Validate webhooks** - Always verify the consumer secret header
255+
5. **Use HTTPS** - Webhook URLs must use HTTPS for security
256+
6. **Monitor usage** - Track API usage to stay within rate limits
257+
7. **Version control** - Document your chainhook configurations
258+
8. **Clean up** - Delete unused chainhooks to reduce costs
259+
260+
## Pagination
261+
262+
List endpoints support pagination via query parameters:
263+
264+
```bash
265+
# Get first page (default: 20 results)
266+
curl "https://api.testnet.hiro.so/chainhooks/v1/me/?limit=20&offset=0" \
267+
-H "x-api-key: YOUR_API_KEY"
268+
269+
# Get next page
270+
curl "https://api.testnet.hiro.so/chainhooks/v1/me/?limit=20&offset=20" \
271+
-H "x-api-key: YOUR_API_KEY"
272+
```
273+
274+
Response includes pagination metadata:
275+
276+
```json
277+
{
278+
"limit": 20,
279+
"offset": 0,
280+
"total": 45,
281+
"results": [...]
282+
}
283+
```
284+
285+
## Next Steps
286+
287+
- [API Reference](https://docs.hiro.so/en/apis/chainhooks-api/reference/chainhooks): Complete endpoint documentation
288+
- [Filter Reference](https://docs.hiro.so/en/tools/chainhooks/reference/filters): Event filter syntax

0 commit comments

Comments
 (0)