@helium/blockchain-api 0.1.3 → 0.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @helium/blockchain-api
2
2
 
3
- TypeScript types and Zod schemas for the Helium Blockchain API. Provides full type safety when building clients for the Helium blockchain services.
3
+ TypeScript client and schemas for the Helium Blockchain API.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,98 +10,122 @@ npm install @helium/blockchain-api
10
10
  yarn add @helium/blockchain-api
11
11
  ```
12
12
 
13
- ## Peer Dependencies
13
+ ## Quick Start
14
14
 
15
- - `@orpc/client` ^1.12.0
16
- - `zod` ^4.0.0
15
+ ```typescript
16
+ import { createClient } from "@helium/blockchain-api";
17
17
 
18
- ## Usage
18
+ const client = createClient({
19
+ url: "https://api.helium.com",
20
+ transport: "rpc",
21
+ });
19
22
 
20
- ### Setting up a typed client
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
+ ```
21
36
 
22
- ```typescript
23
- import type { BlockchainAPIClient } from "@helium/blockchain-api"
24
- import { createORPCClient } from "@orpc/client"
25
- import { RPCLink } from "@orpc/client/fetch"
37
+ ## Authentication
26
38
 
27
- const link = new RPCLink({
28
- url: "https://your-api-url.com/rpc",
29
- })
39
+ For protected endpoints, provide a context factory:
30
40
 
31
- const client: BlockchainAPIClient = createORPCClient(link)
41
+ ```typescript
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
+ });
32
51
  ```
33
52
 
34
- ### Example API calls
53
+ Or use an access token:
35
54
 
36
55
  ```typescript
37
- // Get token balances
38
- const balances = await client.tokens.getBalances({
39
- walletAddress: "your-wallet-address"
40
- })
41
-
42
- // Get swap quote
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
- })
56
+ const client = createClient({
57
+ url: "https://api.helium.com",
58
+ accessToken: "your-access-token",
59
+ });
53
60
  ```
54
61
 
55
- ### Using Zod schemas for validation
62
+ ## Schema Validation
63
+
64
+ All Zod schemas are exported for direct use:
56
65
 
57
66
  ```typescript
58
- import { HotspotSchema, TokenAccountSchema } from "@helium/blockchain-api"
67
+ import {
68
+ GetBalancesInputSchema,
69
+ TokenBalanceDataSchema,
70
+ } from "@helium/blockchain-api";
71
+
72
+ // Validate input
73
+ const input = GetBalancesInputSchema.parse({
74
+ walletAddress: userInput,
75
+ });
76
+ ```
77
+
78
+ ## Error Handling
59
79
 
60
- // Validate data
61
- const hotspot = HotspotSchema.parse(rawData)
80
+ Typed error definitions are available:
62
81
 
63
- // Type inference
64
- type Hotspot = z.infer<typeof HotspotSchema>
82
+ ```typescript
83
+ import { createClient, INSUFFICIENT_FUNDS, solanaErrors } from "@helium/blockchain-api";
84
+
85
+ try {
86
+ await client.tokens.transfer({ ... });
87
+ } catch (error) {
88
+ if (error.code === INSUFFICIENT_FUNDS.code) {
89
+ console.error("Not enough SOL:", error.data);
90
+ }
91
+ }
65
92
  ```
66
93
 
67
- ### With TanStack Query
94
+ ## Testing with Mock Client
68
95
 
69
96
  ```typescript
70
- import { createRouterUtils } from "@orpc/tanstack-query"
97
+ import { createMockClient } from "@helium/blockchain-api";
98
+
99
+ const mockClient = createMockClient({
100
+ tokens: {
101
+ getBalances: async () => ({
102
+ totalBalanceUsd: 100,
103
+ solBalance: 1,
104
+ solBalanceUsd: 50,
105
+ tokens: [],
106
+ }),
107
+ },
108
+ health: {
109
+ check: async () => ({ ok: true }),
110
+ },
111
+ });
112
+
113
+ // Use in tests
114
+ const result = await mockClient.tokens.getBalances({ walletAddress: "..." });
115
+ ```
71
116
 
72
- const orpc = createRouterUtils(client)
117
+ ## API Reference
73
118
 
74
- // In a React component
75
- const { data, isLoading } = orpc.tokens.getBalances.useQuery({
76
- input: { walletAddress: "your-wallet-address" }
77
- })
78
- ```
119
+ ### Routers
79
120
 
80
- ## Available Routers
81
-
82
- - `hotspots` - Hotspot management, rewards, splits
83
- - `tokens` - Token balances, transfers
84
- - `swap` - Jupiter DEX integration
85
- - `transactions` - Transaction submission/tracking
86
- - `welcomePacks` - Onboarding rewards
87
- - `fiat` - Bank accounts, KYC, offramp
88
- - `health` - Health checks
89
-
90
- ## Exports
91
-
92
- ### Types
93
- - `ORPCRouter` - The full router type
94
- - `BlockchainAPIClient` - Helper type for typed clients
95
- - `RouterClient` - Re-exported from @orpc/server
96
-
97
- ### Zod Schemas
98
- - `HotspotSchema`, `HotspotsDataSchema` - Hotspot data validation
99
- - `TokenAccountSchema`, `TokenBalanceDataSchema` - Token data validation
100
- - `TransactionDataSchema`, `TransactionItemSchema` - Transaction validation
101
- - `QuoteResponseSchema` - Swap quote validation
102
- - `WelcomePackSchema` - Welcome pack validation
103
- - `BankAccountSchema`, `KycStatusOutputSchema` - Fiat/KYC validation
104
- - And many more input/output schemas for each router
121
+ - `health` - Health check
122
+ - `tokens` - Token balances and transfers
123
+ - `hotspots` - Hotspot management and rewards
124
+ - `swap` - Token swaps via Jupiter
125
+ - `transactions` - Transaction submission and tracking
126
+ - `welcomePacks` - Welcome pack management
127
+ - `fiat` - Fiat offramp and bank accounts
128
+ - `webhooks` - Webhook handlers
105
129
 
106
130
  ## License
107
131