@satianurag/hiero-mirror-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/index.cjs +2231 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1425 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +1425 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +1425 -0
- package/dist/index.mjs +2218 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils.cjs +188 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +105 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +105 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.d.ts +105 -0
- package/dist/utils.mjs +178 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 satianurag
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# @satianurag/hiero-mirror-client
|
|
2
|
+
|
|
3
|
+
Standalone TypeScript client for the **Hedera / Hiero Mirror Node REST API**.
|
|
4
|
+
|
|
5
|
+
Built for precision, type safety, and developer ergonomics — no silent data corruption, no manual pagination, no guesswork.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Full API coverage** — 47 methods across 9 resource groups
|
|
10
|
+
- **Safe JSON parsing** — int64 values preserved as strings (no precision loss)
|
|
11
|
+
- **Three pagination patterns** — `await`, `for await...of`, `.pages()`
|
|
12
|
+
- **Adaptive HCS streaming** — topic message polling with auto-backoff
|
|
13
|
+
- **ETag caching** — automatic conditional requests with `If-None-Match`
|
|
14
|
+
- **Typed errors** — structured error hierarchy (`HieroNotFoundError`, `HieroRateLimitError`, etc.)
|
|
15
|
+
- **Dual output** — ESM + CJS with full `.d.ts` declarations
|
|
16
|
+
- **Zero platform dependencies** — works in Node.js 18+, Deno, Bun, and browsers
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @satianurag/hiero-mirror-client
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { MirrorNodeClient } from '@satianurag/hiero-mirror-client';
|
|
28
|
+
|
|
29
|
+
const client = new MirrorNodeClient({ network: 'mainnet' });
|
|
30
|
+
|
|
31
|
+
// Get an account
|
|
32
|
+
const account = await client.accounts.get('0.0.800');
|
|
33
|
+
console.log(account.balance);
|
|
34
|
+
|
|
35
|
+
// List tokens (first page)
|
|
36
|
+
const page = await client.tokens.list({ limit: 10 });
|
|
37
|
+
console.log(page.data);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Pagination
|
|
41
|
+
|
|
42
|
+
Three ergonomic patterns for consuming paginated results:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// 1. Await — get the first page
|
|
46
|
+
const firstPage = await client.accounts.list({ limit: 25 });
|
|
47
|
+
console.log(firstPage.data); // AccountSummary[]
|
|
48
|
+
console.log(firstPage.links.next); // cursor or null
|
|
49
|
+
|
|
50
|
+
// 2. Auto-paginate items
|
|
51
|
+
for await (const account of client.accounts.list()) {
|
|
52
|
+
console.log(account.account);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 3. Page-by-page
|
|
56
|
+
for await (const page of client.accounts.list({ limit: 100 }).pages()) {
|
|
57
|
+
console.log(`Got ${page.data.length} accounts`);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Topic Streaming
|
|
62
|
+
|
|
63
|
+
Subscribe to Hedera Consensus Service messages with adaptive polling:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const controller = new AbortController();
|
|
67
|
+
|
|
68
|
+
for await (const msg of client.topics.stream('0.0.12345', {
|
|
69
|
+
signal: controller.signal,
|
|
70
|
+
})) {
|
|
71
|
+
console.log(msg.consensus_timestamp, msg.message);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Cancel anytime
|
|
75
|
+
controller.abort();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Error Handling
|
|
79
|
+
|
|
80
|
+
All errors extend `HieroError` for easy pattern matching:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import {
|
|
84
|
+
HieroNotFoundError,
|
|
85
|
+
HieroRateLimitError,
|
|
86
|
+
HieroValidationError,
|
|
87
|
+
} from '@satianurag/hiero-mirror-client';
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await client.accounts.get('0.0.999999999');
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error instanceof HieroNotFoundError) {
|
|
93
|
+
console.log('Account not found');
|
|
94
|
+
} else if (error instanceof HieroRateLimitError) {
|
|
95
|
+
console.log(`Rate limited, retry after ${error.retryAfter}ms`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Configuration
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const client = new MirrorNodeClient({
|
|
104
|
+
// Network preset (or use baseUrl for custom)
|
|
105
|
+
network: 'testnet', // 'mainnet' | 'testnet' | 'previewnet'
|
|
106
|
+
// baseUrl: 'https://custom-mirror.example.com',
|
|
107
|
+
|
|
108
|
+
timeout: 30_000, // Request timeout (default: 30s)
|
|
109
|
+
maxRetries: 2, // Retry count (default: 2)
|
|
110
|
+
rateLimitRps: 50, // Rate limit (default: 50 req/s)
|
|
111
|
+
logger: console, // Optional logger (silent by default)
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Network URLs
|
|
116
|
+
|
|
117
|
+
| Network | URL |
|
|
118
|
+
|---------|-----|
|
|
119
|
+
| `mainnet` | `https://mainnet-public.mirrornode.hedera.com` |
|
|
120
|
+
| `testnet` | `https://testnet.mirrornode.hedera.com` |
|
|
121
|
+
| `previewnet` | `https://previewnet.mirrornode.hedera.com` |
|
|
122
|
+
|
|
123
|
+
## Resources
|
|
124
|
+
|
|
125
|
+
| Resource | Methods | Key Operations |
|
|
126
|
+
|----------|---------|----------------|
|
|
127
|
+
| `accounts` | 10 | list, get, NFTs, tokens, rewards, allowances, airdrops |
|
|
128
|
+
| `balances` | 1 | list |
|
|
129
|
+
| `blocks` | 2 | list, get |
|
|
130
|
+
| `contracts` | 12 | list, get, call (POST), results, actions, logs, state |
|
|
131
|
+
| `network` | 6 | exchangeRate, fees, nodes, stake, supply |
|
|
132
|
+
| `schedules` | 2 | list, get |
|
|
133
|
+
| `tokens` | 6 | list, get, balances, NFTs, NFT transactions |
|
|
134
|
+
| `topics` | 5 | get, messages, stream |
|
|
135
|
+
| `transactions` | 2 | list, get |
|
|
136
|
+
|
|
137
|
+
## Utilities
|
|
138
|
+
|
|
139
|
+
Additional utilities available via the `/utils` subpath:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { base64ToHex, hexToBase64, fromString, toDate } from '@satianurag/hiero-mirror-client/utils';
|
|
143
|
+
|
|
144
|
+
// Encoding conversions
|
|
145
|
+
const hex = base64ToHex('bZL5Ig=='); // '0x6d92f922'
|
|
146
|
+
|
|
147
|
+
// Timestamp handling with full nanosecond precision
|
|
148
|
+
const ts = fromString('1710000000.123456789');
|
|
149
|
+
ts.seconds; // 1710000000n (BigInt)
|
|
150
|
+
ts.nanos; // 123456789
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## TypeScript
|
|
154
|
+
|
|
155
|
+
All types are exported for full TypeScript support:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import type {
|
|
159
|
+
AccountDetail,
|
|
160
|
+
TokenSummary,
|
|
161
|
+
Transaction,
|
|
162
|
+
NetworkStake,
|
|
163
|
+
} from '@satianurag/hiero-mirror-client';
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Int64 Safety
|
|
167
|
+
|
|
168
|
+
The SDK automatically preserves precision for all large integer values. Fields like `balance`, `stake`, and `total_supply` that exceed `Number.MAX_SAFE_INTEGER` are returned as strings — never silently truncated.
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT
|