@psalomo/jsonrpc-client 0.3.0 → 0.5.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 +47 -7
- package/dist/__tests__/test-utils.d.ts +5 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -0
- package/dist/browser-standalone-mini.js +1245 -0
- package/dist/browser-standalone-mini.min.js +1 -0
- package/dist/browser-standalone.js +5751 -13538
- package/dist/browser-standalone.min.js +1 -0
- package/dist/client.d.ts +57 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.mini.d.ts +58 -0
- package/dist/client.mini.d.ts.map +1 -0
- package/dist/convenience.mini.d.ts +21 -0
- package/dist/convenience.mini.d.ts.map +1 -0
- package/dist/generated-functions.mini.d.ts +3 -0
- package/dist/generated-functions.mini.d.ts.map +1 -0
- package/dist/generated-types.d.ts +55 -0
- package/dist/generated-types.d.ts.map +1 -0
- package/dist/generated-types.mini.d.ts +84 -0
- package/dist/generated-types.mini.d.ts.map +1 -0
- package/dist/index.d.mts +65 -170
- package/dist/index.d.ts +7 -241
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -161
- package/dist/index.mini.cjs +421 -0
- package/dist/index.mini.d.mts +198 -0
- package/dist/index.mini.d.ts +10 -0
- package/dist/index.mini.d.ts.map +1 -0
- package/dist/index.mini.mjs +361 -0
- package/dist/index.mjs +44 -161
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validation.mini.d.ts +12 -0
- package/dist/validation.mini.d.ts.map +1 -0
- package/package.json +16 -6
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# `@near-js/jsonrpc-client`
|
2
2
|
|
3
|
-
This package provides a fully-typed client for the NEAR Protocol JSON-RPC API.
|
3
|
+
This package provides a fully-typed, dynamic client for the NEAR Protocol JSON-RPC API. All methods and types are automatically generated from the official OpenAPI specification.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -13,9 +13,11 @@ pnpm add @near-js/jsonrpc-client
|
|
13
13
|
Create a new client instance and call any of the available RPC methods:
|
14
14
|
|
15
15
|
```typescript
|
16
|
-
import {
|
16
|
+
import { NearRpcClient } from '@near-js/jsonrpc-client';
|
17
17
|
|
18
|
-
const client = new
|
18
|
+
const client = new NearRpcClient({
|
19
|
+
endpoint: 'https://rpc.mainnet.near.org'
|
20
|
+
});
|
19
21
|
|
20
22
|
async function getNetworkStatus() {
|
21
23
|
const status = await client.status();
|
@@ -27,17 +29,55 @@ getNetworkStatus();
|
|
27
29
|
|
28
30
|
### Handling Responses
|
29
31
|
|
30
|
-
All method calls return a promise that resolves to a
|
32
|
+
All method calls return a promise that resolves to a fully typed result object based on the JSON-RPC API specification.
|
31
33
|
|
32
34
|
```typescript
|
33
|
-
import {
|
35
|
+
import { NearRpcClient } from '@near-js/jsonrpc-client';
|
34
36
|
|
35
|
-
const client = new
|
37
|
+
const client = new NearRpcClient({
|
38
|
+
endpoint: 'https://rpc.mainnet.near.org'
|
39
|
+
});
|
36
40
|
|
37
41
|
async function getLatestBlock() {
|
38
42
|
const block = await client.block({ finality: 'final' });
|
39
|
-
console.log('Latest block:', block);
|
43
|
+
console.log('Latest block height:', block.header?.height);
|
40
44
|
}
|
41
45
|
|
42
46
|
getLatestBlock();
|
43
47
|
```
|
48
|
+
|
49
|
+
### Convenience Methods
|
50
|
+
|
51
|
+
The client includes convenience methods for common query operations:
|
52
|
+
|
53
|
+
```typescript
|
54
|
+
// View account information
|
55
|
+
const account = await client.viewAccount({
|
56
|
+
accountId: 'example.near',
|
57
|
+
finality: 'final'
|
58
|
+
});
|
59
|
+
console.log('Account balance:', account.amount);
|
60
|
+
console.log('Storage used:', account.storageUsage);
|
61
|
+
|
62
|
+
// Call view functions
|
63
|
+
const result = await client.viewFunction({
|
64
|
+
accountId: 'contract.near',
|
65
|
+
methodName: 'get_balance',
|
66
|
+
finality: 'final'
|
67
|
+
});
|
68
|
+
|
69
|
+
// View access keys
|
70
|
+
const accessKey = await client.viewAccessKey({
|
71
|
+
accountId: 'example.near',
|
72
|
+
publicKey: 'ed25519:...',
|
73
|
+
finality: 'final'
|
74
|
+
});
|
75
|
+
```
|
76
|
+
|
77
|
+
## Features
|
78
|
+
|
79
|
+
- **🔧 Dynamic methods**: All 28+ RPC methods automatically available
|
80
|
+
- **📝 Fully typed**: Complete TypeScript support with proper request/response types
|
81
|
+
- **🔄 Auto-updating**: New API methods appear automatically without code changes
|
82
|
+
- **✅ Runtime validation**: Built-in parameter validation with helpful error messages
|
83
|
+
- **🎯 Convenience methods**: Simplified methods for common operations like `viewAccount`
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export declare function camelToSnake(str: string): string;
|
2
|
+
export declare function snakeToCamel(str: string): string;
|
3
|
+
export declare function convertKeysToSnakeCase(obj: any): any;
|
4
|
+
export declare function convertKeysToCamelCase(obj: any): any;
|
5
|
+
//# sourceMappingURL=test-utils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/__tests__/test-utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAepD;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAepD"}
|