@helium/blockchain-api 0.2.3 → 0.3.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.
Files changed (4) hide show
  1. package/README.md +20 -74
  2. package/dist/index.d.ts +3940 -2763
  3. package/dist/index.js +523 -264
  4. package/package.json +4 -11
package/README.md CHANGED
@@ -13,50 +13,25 @@ yarn add @helium/blockchain-api
13
13
  ## Quick Start
14
14
 
15
15
  ```typescript
16
- import { createClient } from "@helium/blockchain-api";
17
-
18
- const client = createClient({
19
- url: "https://api.helium.com",
20
- transport: "rpc",
21
- });
22
-
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
- ```
36
-
37
- ## Authentication
38
-
39
- For protected endpoints, provide a context factory:
40
-
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,
16
+ import { apiContract } from "@helium/blockchain-api";
17
+ import { createORPCClient, onError } from "@orpc/client";
18
+ import { RPCLink } from "@orpc/client/fetch";
19
+ import { ContractRouterClient } from "@orpc/contract";
20
+
21
+ const link = new RPCLink({
22
+ url: "<RPC_URL>",
23
+ headers: () => ({
24
+ //...
49
25
  }),
26
+ // fetch: <-- provide fetch polyfill fetch if needed
27
+ interceptors: [
28
+ onError((error) => {
29
+ console.error(error);
30
+ }),
31
+ ],
50
32
  });
51
- ```
52
-
53
- Or use an access token:
54
-
55
- ```typescript
56
- const client = createClient({
57
- url: "https://api.helium.com",
58
- accessToken: "your-access-token",
59
- });
33
+ // Create a client using an imported contract
34
+ const client: ContractRouterClient<typeof apiContract> = createORPCClient(link);
60
35
  ```
61
36
 
62
37
  ## Schema Validation
@@ -77,41 +52,12 @@ const input = GetBalancesInputSchema.parse({
77
52
 
78
53
  ## Error Handling
79
54
 
80
- Typed error definitions are available:
81
-
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
- }
92
- ```
55
+ See https://orpc.dev/docs/client/error-handling
93
56
 
94
- ## Testing with Mock Client
57
+ Typed error definitions are available:
95
58
 
96
59
  ```typescript
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: "..." });
60
+ import { INSUFFICIENT_FUNDS } from "@helium/blockchain-api";
115
61
  ```
116
62
 
117
63
  ## API Reference