@helium/blockchain-api 0.1.2 → 0.2.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/README.md +106 -49
- package/dist/index.d.ts +2382 -0
- package/dist/index.js +852 -0
- package/package.json +36 -126
- package/src/server/api/errors.ts +0 -152
- package/src/server/api/index.ts +0 -40
- package/src/server/api/procedures.ts +0 -144
- package/src/server/api/routers/fiat/router.ts +0 -709
- package/src/server/api/routers/fiat/schemas.ts +0 -169
- package/src/server/api/routers/health/router.ts +0 -41
- package/src/server/api/routers/hotspots/procedures/claimRewards.ts +0 -258
- package/src/server/api/routers/hotspots/procedures/createSplit.ts +0 -253
- package/src/server/api/routers/hotspots/procedures/deleteSplit.ts +0 -156
- package/src/server/api/routers/hotspots/procedures/getHotspots.ts +0 -31
- package/src/server/api/routers/hotspots/procedures/getPendingRewards.ts +0 -44
- package/src/server/api/routers/hotspots/procedures/getSplit.ts +0 -88
- package/src/server/api/routers/hotspots/procedures/transferHotspot.ts +0 -204
- package/src/server/api/routers/hotspots/procedures/updateRewardsDestination.ts +0 -201
- package/src/server/api/routers/hotspots/router.ts +0 -30
- package/src/server/api/routers/hotspots/schemas.ts +0 -182
- package/src/server/api/routers/swap/procedures/getInstructions.ts +0 -152
- package/src/server/api/routers/swap/procedures/getQuote.ts +0 -53
- package/src/server/api/routers/swap/procedures/getTokens.ts +0 -88
- package/src/server/api/routers/swap/router.ts +0 -15
- package/src/server/api/routers/swap/schemas.ts +0 -96
- package/src/server/api/routers/tokens/procedures/createHntAccount.ts +0 -87
- package/src/server/api/routers/tokens/procedures/getBalances.ts +0 -27
- package/src/server/api/routers/tokens/procedures/transfer.ts +0 -159
- package/src/server/api/routers/tokens/router.ts +0 -15
- package/src/server/api/routers/tokens/schemas.ts +0 -80
- package/src/server/api/routers/transactions/procedures/get.ts +0 -46
- package/src/server/api/routers/transactions/procedures/getByPayer.ts +0 -111
- package/src/server/api/routers/transactions/procedures/getByPayerAndTag.ts +0 -119
- package/src/server/api/routers/transactions/procedures/resubmit.ts +0 -68
- package/src/server/api/routers/transactions/procedures/submit.ts +0 -216
- package/src/server/api/routers/transactions/router.ts +0 -21
- package/src/server/api/routers/transactions/schemas.ts +0 -119
- package/src/server/api/routers/webhooks/router.ts +0 -75
- package/src/server/api/routers/welcomePacks/procedures/claim.ts +0 -157
- package/src/server/api/routers/welcomePacks/procedures/create.ts +0 -247
- package/src/server/api/routers/welcomePacks/procedures/deletePack.ts +0 -118
- package/src/server/api/routers/welcomePacks/procedures/get.ts +0 -36
- package/src/server/api/routers/welcomePacks/procedures/getByAddress.ts +0 -26
- package/src/server/api/routers/welcomePacks/procedures/invite.ts +0 -44
- package/src/server/api/routers/welcomePacks/procedures/list.ts +0 -27
- package/src/server/api/routers/welcomePacks/router.ts +0 -27
- package/src/server/api/routers/welcomePacks/schemas.ts +0 -135
- package/src/server/api/schemas.ts +0 -281
- package/tsconfig.json +0 -45
- package/types/README.md +0 -86
- package/types/index.ts +0 -27
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @helium/blockchain-api
|
|
2
2
|
|
|
3
|
-
TypeScript
|
|
3
|
+
TypeScript client and schemas for the Helium Blockchain API.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,76 +10,133 @@ npm install @helium/blockchain-api
|
|
|
10
10
|
yarn add @helium/blockchain-api
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Quick Start
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
```typescript
|
|
16
|
+
import { createClient } from "@helium/blockchain-api";
|
|
17
|
+
|
|
18
|
+
const client = createClient({
|
|
19
|
+
url: "https://api.helium.com",
|
|
20
|
+
transport: "rpc",
|
|
21
|
+
});
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
// Get token balances
|
|
24
|
+
const balances = await client.tokens.getBalances({
|
|
25
|
+
walletAddress: "YOUR_WALLET_ADDRESS",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Get hotspots
|
|
29
|
+
const hotspots = await client.hotspots.getHotspots({
|
|
30
|
+
walletAddress: "YOUR_WALLET_ADDRESS",
|
|
31
|
+
type: "iot",
|
|
32
|
+
page: 1,
|
|
33
|
+
limit: 20,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
19
36
|
|
|
20
|
-
|
|
37
|
+
## Authentication
|
|
38
|
+
|
|
39
|
+
For protected endpoints, provide a context factory:
|
|
21
40
|
|
|
22
41
|
```typescript
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
const client = createClient({
|
|
43
|
+
url: "https://api.helium.com",
|
|
44
|
+
transport: "rpc",
|
|
45
|
+
getContext: () => ({
|
|
46
|
+
userId: currentUser.id,
|
|
47
|
+
walletAddress: connectedWallet?.address ?? null,
|
|
48
|
+
user: privyUser,
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
```
|
|
26
52
|
|
|
27
|
-
|
|
28
|
-
url: "https://your-api-url.com/rpc",
|
|
29
|
-
})
|
|
53
|
+
Or use an access token:
|
|
30
54
|
|
|
31
|
-
|
|
55
|
+
```typescript
|
|
56
|
+
const client = createClient({
|
|
57
|
+
url: "https://api.helium.com",
|
|
58
|
+
accessToken: "your-access-token",
|
|
59
|
+
});
|
|
32
60
|
```
|
|
33
61
|
|
|
34
|
-
|
|
62
|
+
## Schema Validation
|
|
63
|
+
|
|
64
|
+
All Zod schemas are exported for direct use:
|
|
35
65
|
|
|
36
66
|
```typescript
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const quote = await client.swap.getQuote({
|
|
44
|
-
inputMint: "input-token-mint",
|
|
45
|
-
outputMint: "output-token-mint",
|
|
46
|
-
amount: "1000000"
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// Claim hotspot rewards
|
|
50
|
-
const { transactionData } = await client.hotspots.claimRewards({
|
|
51
|
-
walletAddress: "your-wallet-address"
|
|
52
|
-
})
|
|
67
|
+
import { GetBalancesInputSchema, TokenBalanceDataSchema } from "@helium/blockchain-api";
|
|
68
|
+
|
|
69
|
+
// Validate input
|
|
70
|
+
const input = GetBalancesInputSchema.parse({
|
|
71
|
+
walletAddress: userInput,
|
|
72
|
+
});
|
|
53
73
|
```
|
|
54
74
|
|
|
55
|
-
|
|
75
|
+
## Error Handling
|
|
76
|
+
|
|
77
|
+
Typed error definitions are available:
|
|
56
78
|
|
|
57
79
|
```typescript
|
|
58
|
-
import {
|
|
80
|
+
import { createClient, INSUFFICIENT_FUNDS, solanaErrors } from "@helium/blockchain-api";
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
await client.tokens.transfer({ ... });
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error.code === INSUFFICIENT_FUNDS.code) {
|
|
86
|
+
console.error("Not enough SOL:", error.data);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
59
90
|
|
|
60
|
-
|
|
91
|
+
## Testing with Mock Client
|
|
61
92
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
93
|
+
```typescript
|
|
94
|
+
import { createMockClient } from "@helium/blockchain-api";
|
|
95
|
+
|
|
96
|
+
const mockClient = createMockClient({
|
|
97
|
+
tokens: {
|
|
98
|
+
getBalances: async () => ({
|
|
99
|
+
totalBalanceUsd: 100,
|
|
100
|
+
solBalance: 1,
|
|
101
|
+
solBalanceUsd: 50,
|
|
102
|
+
tokens: [],
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
health: {
|
|
106
|
+
check: async () => ({ ok: true }),
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Use in tests
|
|
111
|
+
const result = await mockClient.tokens.getBalances({ walletAddress: "..." });
|
|
66
112
|
```
|
|
67
113
|
|
|
68
|
-
##
|
|
114
|
+
## OpenAPI Spec Generation
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { generateOpenAPISpec } from "@helium/blockchain-api";
|
|
118
|
+
|
|
119
|
+
const spec = generateOpenAPISpec({
|
|
120
|
+
info: {
|
|
121
|
+
title: "Helium Blockchain API",
|
|
122
|
+
version: "1.0.0",
|
|
123
|
+
},
|
|
124
|
+
servers: [{ url: "https://api.helium.com" }],
|
|
125
|
+
});
|
|
126
|
+
```
|
|
69
127
|
|
|
70
|
-
|
|
71
|
-
- `tokens` - Token balances, transfers
|
|
72
|
-
- `swap` - Jupiter DEX integration
|
|
73
|
-
- `transactions` - Transaction submission/tracking
|
|
74
|
-
- `welcomePacks` - Onboarding rewards
|
|
75
|
-
- `fiat` - Bank accounts, KYC, offramp
|
|
76
|
-
- `health` - Health checks
|
|
128
|
+
## API Reference
|
|
77
129
|
|
|
78
|
-
|
|
130
|
+
### Routers
|
|
79
131
|
|
|
80
|
-
- `
|
|
81
|
-
- `
|
|
82
|
-
- `
|
|
132
|
+
- `health` - Health check
|
|
133
|
+
- `tokens` - Token balances and transfers
|
|
134
|
+
- `hotspots` - Hotspot management and rewards
|
|
135
|
+
- `swap` - Token swaps via Jupiter
|
|
136
|
+
- `transactions` - Transaction submission and tracking
|
|
137
|
+
- `welcomePacks` - Welcome pack management
|
|
138
|
+
- `fiat` - Fiat offramp and bank accounts
|
|
139
|
+
- `webhooks` - Webhook handlers
|
|
83
140
|
|
|
84
141
|
## License
|
|
85
142
|
|