@psalomo/jsonrpc-client 0.2.0 → 0.4.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/browser-standalone.js +67 -174
- package/dist/index.d.mts +63 -167
- package/dist/index.d.ts +63 -167
- package/dist/index.js +38 -156
- package/dist/index.mjs +40 -156
- package/package.json +4 -2
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`
|
@@ -14088,6 +14088,12 @@ var BroadcastTxCommitRequestSchema = external_exports.lazy(
|
|
14088
14088
|
var BroadcastTxCommitResponseSchema = external_exports.lazy(
|
14089
14089
|
() => JsonRpcResponseFor_RpcTransactionResponseAnd_RpcErrorSchema
|
14090
14090
|
);
|
14091
|
+
var ChangesRequestSchema = external_exports.lazy(
|
14092
|
+
() => JsonRpcRequestForChangesSchema
|
14093
|
+
);
|
14094
|
+
var ChangesResponseSchema = external_exports.lazy(
|
14095
|
+
() => JsonRpcResponseFor_RpcStateChangesInBlockResponseAnd_RpcErrorSchema
|
14096
|
+
);
|
14091
14097
|
var ChunkRequestSchema = external_exports.lazy(() => JsonRpcRequestForChunkSchema);
|
14092
14098
|
var ChunkResponseSchema = external_exports.lazy(
|
14093
14099
|
() => JsonRpcResponseFor_RpcChunkResponseAnd_RpcErrorSchema
|
@@ -14120,6 +14126,12 @@ var NetworkInfoRequestSchema = external_exports.lazy(
|
|
14120
14126
|
var NetworkInfoResponseSchema = external_exports.lazy(
|
14121
14127
|
() => JsonRpcResponseFor_RpcNetworkInfoResponseAnd_RpcErrorSchema
|
14122
14128
|
);
|
14129
|
+
var NextLightClientBlockRequestSchema = external_exports.lazy(
|
14130
|
+
() => JsonRpcRequestForNextLightClientBlockSchema
|
14131
|
+
);
|
14132
|
+
var NextLightClientBlockResponseSchema = external_exports.lazy(
|
14133
|
+
() => JsonRpcResponseFor_RpcLightClientNextBlockResponseAnd_RpcErrorSchema
|
14134
|
+
);
|
14123
14135
|
var QueryRequestSchema = external_exports.lazy(() => JsonRpcRequestForQuerySchema);
|
14124
14136
|
var QueryResponseSchema = external_exports.lazy(
|
14125
14137
|
() => JsonRpcResponseFor_RpcQueryResponseAnd_RpcErrorSchema
|
@@ -14160,32 +14172,34 @@ var JsonRpcResponseSchema = external_exports.object({
|
|
14160
14172
|
error: JsonRpcErrorSchema.optional()
|
14161
14173
|
});
|
14162
14174
|
var PATH_TO_METHOD_MAP = {
|
14175
|
+
"/EXPERIMENTAL_changes": "EXPERIMENTAL_changes",
|
14176
|
+
"/EXPERIMENTAL_changes_in_block": "EXPERIMENTAL_changes_in_block",
|
14177
|
+
"/EXPERIMENTAL_congestion_level": "EXPERIMENTAL_congestion_level",
|
14178
|
+
"/EXPERIMENTAL_genesis_config": "EXPERIMENTAL_genesis_config",
|
14179
|
+
"/EXPERIMENTAL_light_client_block_proof": "EXPERIMENTAL_light_client_block_proof",
|
14180
|
+
"/EXPERIMENTAL_light_client_proof": "EXPERIMENTAL_light_client_proof",
|
14181
|
+
"/EXPERIMENTAL_maintenance_windows": "EXPERIMENTAL_maintenance_windows",
|
14182
|
+
"/EXPERIMENTAL_protocol_config": "EXPERIMENTAL_protocol_config",
|
14183
|
+
"/EXPERIMENTAL_receipt": "EXPERIMENTAL_receipt",
|
14184
|
+
"/EXPERIMENTAL_split_storage_info": "EXPERIMENTAL_split_storage_info",
|
14185
|
+
"/EXPERIMENTAL_tx_status": "EXPERIMENTAL_tx_status",
|
14186
|
+
"/EXPERIMENTAL_validators_ordered": "EXPERIMENTAL_validators_ordered",
|
14163
14187
|
"/block": "block",
|
14188
|
+
"/broadcast_tx_async": "broadcast_tx_async",
|
14189
|
+
"/broadcast_tx_commit": "broadcast_tx_commit",
|
14190
|
+
"/changes": "changes",
|
14164
14191
|
"/chunk": "chunk",
|
14192
|
+
"/client_config": "client_config",
|
14165
14193
|
"/gas_price": "gas_price",
|
14166
|
-
"/status": "status",
|
14167
14194
|
"/health": "health",
|
14195
|
+
"/light_client_proof": "light_client_proof",
|
14168
14196
|
"/network_info": "network_info",
|
14169
|
-
"/
|
14170
|
-
"/
|
14171
|
-
"/broadcast_tx_async": "broadcast_tx_async",
|
14172
|
-
"/broadcast_tx_commit": "broadcast_tx_commit",
|
14197
|
+
"/next_light_client_block": "next_light_client_block",
|
14198
|
+
"/query": "query",
|
14173
14199
|
"/send_tx": "send_tx",
|
14200
|
+
"/status": "status",
|
14174
14201
|
"/tx": "tx",
|
14175
|
-
"/
|
14176
|
-
"/light_client_proof": "light_client_proof",
|
14177
|
-
"/EXPERIMENTAL_changes": "EXPERIMENTAL_changes",
|
14178
|
-
"/EXPERIMENTAL_changes_in_block": "EXPERIMENTAL_changes_in_block",
|
14179
|
-
"/EXPERIMENTAL_validators_ordered": "EXPERIMENTAL_validators_ordered",
|
14180
|
-
"/EXPERIMENTAL_protocol_config": "EXPERIMENTAL_protocol_config",
|
14181
|
-
"/EXPERIMENTAL_genesis_config": "EXPERIMENTAL_genesis_config",
|
14182
|
-
"/EXPERIMENTAL_light_client_proof": "EXPERIMENTAL_light_client_proof",
|
14183
|
-
"/EXPERIMENTAL_light_client_block_proof": "EXPERIMENTAL_light_client_block_proof",
|
14184
|
-
"/EXPERIMENTAL_receipt": "EXPERIMENTAL_receipt",
|
14185
|
-
"/EXPERIMENTAL_tx_status": "EXPERIMENTAL_tx_status",
|
14186
|
-
"/EXPERIMENTAL_split_storage_info": "EXPERIMENTAL_split_storage_info",
|
14187
|
-
"/EXPERIMENTAL_congestion_level": "EXPERIMENTAL_congestion_level",
|
14188
|
-
"/EXPERIMENTAL_maintenance_windows": "EXPERIMENTAL_maintenance_windows"
|
14202
|
+
"/validators": "validators"
|
14189
14203
|
};
|
14190
14204
|
var METHOD_TO_PATH_MAP = {};
|
14191
14205
|
Object.entries(PATH_TO_METHOD_MAP).forEach(([path, method]) => {
|
@@ -14278,6 +14292,7 @@ var NearRpcClient = class {
|
|
14278
14292
|
}
|
14279
14293
|
/**
|
14280
14294
|
* Make a raw JSON-RPC call
|
14295
|
+
* This method is public to allow dynamic calls to any RPC method
|
14281
14296
|
*/
|
14282
14297
|
async call(method, params) {
|
14283
14298
|
const requestId = this.generateRequestId();
|
@@ -14350,162 +14365,38 @@ var NearRpcClient = class {
|
|
14350
14365
|
lastError
|
14351
14366
|
);
|
14352
14367
|
}
|
14353
|
-
|
14354
|
-
|
14355
|
-
|
14356
|
-
|
14357
|
-
|
14358
|
-
|
14359
|
-
|
14360
|
-
|
14361
|
-
|
14362
|
-
|
14363
|
-
*/
|
14364
|
-
async block(params) {
|
14365
|
-
return this.call("block", params);
|
14366
|
-
}
|
14367
|
-
/**
|
14368
|
-
* Get current gas price
|
14369
|
-
*/
|
14370
|
-
async gasPrice(params) {
|
14371
|
-
return this.call("gas_price", params);
|
14372
|
-
}
|
14373
|
-
/**
|
14374
|
-
* Get chunk information
|
14375
|
-
*/
|
14376
|
-
async chunk(params) {
|
14377
|
-
return this.call("chunk", params);
|
14378
|
-
}
|
14379
|
-
/**
|
14380
|
-
* Health check
|
14381
|
-
*/
|
14382
|
-
async health() {
|
14383
|
-
return this.call("health");
|
14384
|
-
}
|
14385
|
-
/**
|
14386
|
-
* Get network information
|
14387
|
-
*/
|
14388
|
-
async networkInfo() {
|
14389
|
-
return this.call("network_info");
|
14390
|
-
}
|
14391
|
-
/**
|
14392
|
-
* Get current validators
|
14393
|
-
*/
|
14394
|
-
async validators(params) {
|
14395
|
-
return this.call("validators", params);
|
14396
|
-
}
|
14397
|
-
/**
|
14398
|
-
* Get client configuration
|
14399
|
-
*/
|
14400
|
-
async clientConfig() {
|
14401
|
-
return this.call("client_config");
|
14402
|
-
}
|
14403
|
-
/**
|
14404
|
-
* Broadcast transaction asynchronously
|
14405
|
-
*/
|
14406
|
-
async broadcastTxAsync(params) {
|
14407
|
-
return this.call("broadcast_tx_async", params);
|
14408
|
-
}
|
14409
|
-
/**
|
14410
|
-
* Broadcast transaction and wait for commit
|
14411
|
-
*/
|
14412
|
-
async broadcastTxCommit(params) {
|
14413
|
-
return this.call("broadcast_tx_commit", params);
|
14414
|
-
}
|
14415
|
-
/**
|
14416
|
-
* Send transaction
|
14417
|
-
*/
|
14418
|
-
async sendTx(params) {
|
14419
|
-
return await this.call("send_tx", params);
|
14420
|
-
}
|
14421
|
-
/**
|
14422
|
-
* Get transaction status
|
14423
|
-
*/
|
14424
|
-
async tx(params) {
|
14425
|
-
return this.call("tx", params);
|
14426
|
-
}
|
14427
|
-
/**
|
14428
|
-
* Query account/contract state
|
14429
|
-
*/
|
14430
|
-
async query(params) {
|
14431
|
-
return this.call("query", params);
|
14432
|
-
}
|
14433
|
-
/**
|
14434
|
-
* View account information (convenience method)
|
14435
|
-
*/
|
14436
|
-
async viewAccount(params) {
|
14437
|
-
return this.query({
|
14438
|
-
requestType: "view_account",
|
14439
|
-
...params
|
14440
|
-
});
|
14441
|
-
}
|
14442
|
-
/**
|
14443
|
-
* View function call (convenience method)
|
14444
|
-
*/
|
14445
|
-
async viewFunction(params) {
|
14446
|
-
return this.query({
|
14447
|
-
requestType: "call_function",
|
14448
|
-
...params
|
14449
|
-
});
|
14450
|
-
}
|
14451
|
-
/**
|
14452
|
-
* View access key (convenience method)
|
14453
|
-
*/
|
14454
|
-
async viewAccessKey(params) {
|
14455
|
-
return this.query({
|
14456
|
-
requestType: "view_access_key",
|
14457
|
-
...params
|
14458
|
-
});
|
14459
|
-
}
|
14460
|
-
/**
|
14461
|
-
* Get light client proof
|
14462
|
-
*/
|
14463
|
-
async lightClientProof(params) {
|
14464
|
-
return this.call("light_client_proof", params);
|
14465
|
-
}
|
14466
|
-
// Experimental methods
|
14467
|
-
/**
|
14468
|
-
* Get state changes (experimental)
|
14469
|
-
*/
|
14470
|
-
async experimentalChanges(params) {
|
14471
|
-
return this.call("EXPERIMENTAL_changes", params);
|
14472
|
-
}
|
14473
|
-
/**
|
14474
|
-
* Get state changes in block (experimental)
|
14475
|
-
*/
|
14476
|
-
async experimentalChangesInBlock(params) {
|
14477
|
-
return this.call("EXPERIMENTAL_changes_in_block", params);
|
14478
|
-
}
|
14479
|
-
/**
|
14480
|
-
* Get ordered validators (experimental)
|
14481
|
-
*/
|
14482
|
-
async experimentalValidatorsOrdered(params) {
|
14483
|
-
return this.call("EXPERIMENTAL_validators_ordered", params);
|
14484
|
-
}
|
14485
|
-
/**
|
14486
|
-
* Get protocol configuration (experimental)
|
14487
|
-
*/
|
14488
|
-
async experimentalProtocolConfig(params) {
|
14489
|
-
return this.call("EXPERIMENTAL_protocol_config", params);
|
14490
|
-
}
|
14491
|
-
/**
|
14492
|
-
* Get genesis configuration (experimental)
|
14493
|
-
*/
|
14494
|
-
async experimentalGenesisConfig() {
|
14495
|
-
return this.call("EXPERIMENTAL_genesis_config");
|
14496
|
-
}
|
14497
|
-
/**
|
14498
|
-
* Get receipt information (experimental)
|
14499
|
-
*/
|
14500
|
-
async experimentalReceipt(params) {
|
14501
|
-
return this.call("EXPERIMENTAL_receipt", params);
|
14502
|
-
}
|
14503
|
-
/**
|
14504
|
-
* Get transaction status (experimental)
|
14505
|
-
*/
|
14506
|
-
async experimentalTxStatus(params) {
|
14507
|
-
return this.call("EXPERIMENTAL_tx_status", params);
|
14368
|
+
};
|
14369
|
+
RPC_METHODS.forEach((method) => {
|
14370
|
+
let methodName = method;
|
14371
|
+
if (methodName.startsWith("EXPERIMENTAL_")) {
|
14372
|
+
methodName = "experimental" + methodName.substring(13).replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^([a-z])/, (_, letter) => letter.toUpperCase());
|
14373
|
+
} else {
|
14374
|
+
methodName = methodName.replace(
|
14375
|
+
/_([a-z])/g,
|
14376
|
+
(_, letter) => letter.toUpperCase()
|
14377
|
+
);
|
14508
14378
|
}
|
14379
|
+
NearRpcClient.prototype[methodName] = function(params) {
|
14380
|
+
return this.call(method, params);
|
14381
|
+
};
|
14382
|
+
});
|
14383
|
+
NearRpcClient.prototype.viewAccount = function(params) {
|
14384
|
+
return this.query({
|
14385
|
+
requestType: "view_account",
|
14386
|
+
...params
|
14387
|
+
});
|
14388
|
+
};
|
14389
|
+
NearRpcClient.prototype.viewFunction = function(params) {
|
14390
|
+
return this.query({
|
14391
|
+
requestType: "call_function",
|
14392
|
+
...params
|
14393
|
+
});
|
14394
|
+
};
|
14395
|
+
NearRpcClient.prototype.viewAccessKey = function(params) {
|
14396
|
+
return this.query({
|
14397
|
+
requestType: "view_access_key",
|
14398
|
+
...params
|
14399
|
+
});
|
14509
14400
|
};
|
14510
14401
|
|
14511
14402
|
// src/types.ts
|
@@ -14520,6 +14411,8 @@ var NearRpcError = class extends Error {
|
|
14520
14411
|
export {
|
14521
14412
|
JsonRpcClientError,
|
14522
14413
|
JsonRpcNetworkError,
|
14414
|
+
JsonRpcRequestSchema,
|
14415
|
+
JsonRpcResponseSchema,
|
14523
14416
|
NearRpcClient,
|
14524
14417
|
NearRpcError,
|
14525
14418
|
RPC_METHODS,
|
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,61 @@
|
|
1
|
-
|
1
|
+
import { RpcStateChangesInBlockByTypeRequest, RpcStateChangesInBlockResponse, RpcStateChangesInBlockRequest, RpcStateChangesInBlockByTypeResponse, RpcCongestionLevelRequest, RpcCongestionLevelResponse, GenesisConfigRequest, GenesisConfig, RpcLightClientBlockProofRequest, RpcLightClientBlockProofResponse, RpcLightClientExecutionProofRequest, RpcLightClientExecutionProofResponse, RpcMaintenanceWindowsRequest, EXPERIMENTALMaintenanceWindowsResponse, RpcProtocolConfigRequest, RpcProtocolConfigResponse, RpcReceiptRequest, RpcReceiptResponse, RpcSplitStorageInfoRequest, RpcSplitStorageInfoResponse, RpcTransactionStatusRequest, RpcTransactionResponse, RpcValidatorsOrderedRequest, EXPERIMENTALValidatorsOrderedResponse, RpcBlockRequest, RpcBlockResponse, RpcSendTransactionRequest, CryptoHash, RpcChunkRequest, RpcChunkResponse, RpcClientConfigRequest, RpcClientConfigResponse, RpcGasPriceRequest, RpcGasPriceResponse, RpcHealthRequest, RpcHealthResponse, RpcNetworkInfoRequest, RpcNetworkInfoResponse, RpcLightClientNextBlockRequest, RpcLightClientNextBlockResponse, RpcQueryRequest, RpcQueryResponse, RpcStatusRequest, RpcStatusResponse, RpcValidatorRequest, RpcValidatorResponse, AccountView, CallResult, AccessKeyView, RPC_METHODS } from '@near-js/jsonrpc-types';
|
2
|
+
export { JsonRpcRequestSchema, JsonRpcResponseSchema, RPC_METHODS } from '@near-js/jsonrpc-types';
|
2
3
|
|
4
|
+
interface DynamicRpcMethods {
|
5
|
+
experimentalChanges(params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
|
6
|
+
experimentalChangesInBlock(params?: RpcStateChangesInBlockRequest): Promise<RpcStateChangesInBlockByTypeResponse>;
|
7
|
+
experimentalCongestionLevel(params?: RpcCongestionLevelRequest): Promise<RpcCongestionLevelResponse>;
|
8
|
+
experimentalGenesisConfig(params?: GenesisConfigRequest): Promise<GenesisConfig>;
|
9
|
+
experimentalLightClientBlockProof(params?: RpcLightClientBlockProofRequest): Promise<RpcLightClientBlockProofResponse>;
|
10
|
+
experimentalLightClientProof(params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
|
11
|
+
experimentalMaintenanceWindows(params?: RpcMaintenanceWindowsRequest): Promise<EXPERIMENTALMaintenanceWindowsResponse>;
|
12
|
+
experimentalProtocolConfig(params?: RpcProtocolConfigRequest): Promise<RpcProtocolConfigResponse>;
|
13
|
+
experimentalReceipt(params?: RpcReceiptRequest): Promise<RpcReceiptResponse>;
|
14
|
+
experimentalSplitStorageInfo(params?: RpcSplitStorageInfoRequest): Promise<RpcSplitStorageInfoResponse>;
|
15
|
+
experimentalTxStatus(params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
|
16
|
+
experimentalValidatorsOrdered(params?: RpcValidatorsOrderedRequest): Promise<EXPERIMENTALValidatorsOrderedResponse>;
|
17
|
+
block(params?: RpcBlockRequest): Promise<RpcBlockResponse>;
|
18
|
+
broadcastTxAsync(params?: RpcSendTransactionRequest): Promise<CryptoHash>;
|
19
|
+
broadcastTxCommit(params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
|
20
|
+
changes(params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
|
21
|
+
chunk(params?: RpcChunkRequest): Promise<RpcChunkResponse>;
|
22
|
+
clientConfig(params?: RpcClientConfigRequest): Promise<RpcClientConfigResponse>;
|
23
|
+
gasPrice(params?: RpcGasPriceRequest): Promise<RpcGasPriceResponse>;
|
24
|
+
health(params?: RpcHealthRequest): Promise<RpcHealthResponse>;
|
25
|
+
lightClientProof(params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
|
26
|
+
networkInfo(params?: RpcNetworkInfoRequest): Promise<RpcNetworkInfoResponse>;
|
27
|
+
nextLightClientBlock(params?: RpcLightClientNextBlockRequest): Promise<RpcLightClientNextBlockResponse>;
|
28
|
+
query(params?: RpcQueryRequest): Promise<RpcQueryResponse>;
|
29
|
+
sendTx(params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
|
30
|
+
status(params?: RpcStatusRequest): Promise<RpcStatusResponse>;
|
31
|
+
tx(params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
|
32
|
+
validators(params?: RpcValidatorRequest): Promise<RpcValidatorResponse>;
|
33
|
+
}
|
34
|
+
interface ConvenienceMethods {
|
35
|
+
viewAccount(params: {
|
36
|
+
accountId: string;
|
37
|
+
finality?: 'final' | 'near-final' | 'optimistic';
|
38
|
+
blockId?: string | number;
|
39
|
+
}): Promise<AccountView>;
|
40
|
+
viewFunction(params: {
|
41
|
+
accountId: string;
|
42
|
+
methodName: string;
|
43
|
+
argsBase64?: string;
|
44
|
+
finality?: 'final' | 'near-final' | 'optimistic';
|
45
|
+
blockId?: string | number;
|
46
|
+
}): Promise<CallResult>;
|
47
|
+
viewAccessKey(params: {
|
48
|
+
accountId: string;
|
49
|
+
publicKey: string;
|
50
|
+
finality?: 'final' | 'near-final' | 'optimistic';
|
51
|
+
blockId?: string | number;
|
52
|
+
}): Promise<AccessKeyView>;
|
53
|
+
}
|
54
|
+
interface CompleteClientInterface extends DynamicRpcMethods, ConvenienceMethods {
|
55
|
+
call<TParams = unknown, TResult = unknown>(method: string, params?: TParams): Promise<TResult>;
|
56
|
+
}
|
57
|
+
|
58
|
+
type RpcMethod = (typeof RPC_METHODS)[number];
|
3
59
|
interface ClientConfig {
|
4
60
|
endpoint: string;
|
5
61
|
headers?: Record<string, string>;
|
@@ -33,6 +89,7 @@ declare class JsonRpcNetworkError extends Error {
|
|
33
89
|
originalError: Error;
|
34
90
|
constructor(message: string, originalError: Error);
|
35
91
|
}
|
92
|
+
|
36
93
|
declare class NearRpcClient {
|
37
94
|
private endpoint;
|
38
95
|
private headers;
|
@@ -47,172 +104,11 @@ declare class NearRpcClient {
|
|
47
104
|
private generateRequestId;
|
48
105
|
/**
|
49
106
|
* Make a raw JSON-RPC call
|
107
|
+
* This method is public to allow dynamic calls to any RPC method
|
50
108
|
*/
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
*/
|
55
|
-
status(): Promise<any>;
|
56
|
-
/**
|
57
|
-
* Get block information
|
58
|
-
*/
|
59
|
-
block(params?: {
|
60
|
-
blockId?: string | number;
|
61
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
62
|
-
}): Promise<any>;
|
63
|
-
/**
|
64
|
-
* Get current gas price
|
65
|
-
*/
|
66
|
-
gasPrice(params?: {
|
67
|
-
blockId?: string | number;
|
68
|
-
}): Promise<any>;
|
69
|
-
/**
|
70
|
-
* Get chunk information
|
71
|
-
*/
|
72
|
-
chunk(params: {
|
73
|
-
chunkId: string;
|
74
|
-
} | {
|
75
|
-
blockId: string | number;
|
76
|
-
shardId: number;
|
77
|
-
}): Promise<any>;
|
78
|
-
/**
|
79
|
-
* Health check
|
80
|
-
*/
|
81
|
-
health(): Promise<any>;
|
82
|
-
/**
|
83
|
-
* Get network information
|
84
|
-
*/
|
85
|
-
networkInfo(): Promise<any>;
|
86
|
-
/**
|
87
|
-
* Get current validators
|
88
|
-
*/
|
89
|
-
validators(params?: {
|
90
|
-
blockId?: string | number;
|
91
|
-
}): Promise<any>;
|
92
|
-
/**
|
93
|
-
* Get client configuration
|
94
|
-
*/
|
95
|
-
clientConfig(): Promise<any>;
|
96
|
-
/**
|
97
|
-
* Broadcast transaction asynchronously
|
98
|
-
*/
|
99
|
-
broadcastTxAsync(params: {
|
100
|
-
signedTxBase64: string;
|
101
|
-
}): Promise<any>;
|
102
|
-
/**
|
103
|
-
* Broadcast transaction and wait for commit
|
104
|
-
*/
|
105
|
-
broadcastTxCommit(params: {
|
106
|
-
signedTxBase64: string;
|
107
|
-
}): Promise<any>;
|
108
|
-
/**
|
109
|
-
* Send transaction
|
110
|
-
*/
|
111
|
-
sendTx(params: {
|
112
|
-
signedTxBase64: string;
|
113
|
-
}): Promise<any>;
|
114
|
-
/**
|
115
|
-
* Get transaction status
|
116
|
-
*/
|
117
|
-
tx(params: {
|
118
|
-
txHash: string;
|
119
|
-
senderAccountId: string;
|
120
|
-
}): Promise<any>;
|
121
|
-
/**
|
122
|
-
* Query account/contract state
|
123
|
-
*/
|
124
|
-
query(params: {
|
125
|
-
requestType: string;
|
126
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
127
|
-
blockId?: string | number;
|
128
|
-
accountId?: string;
|
129
|
-
methodName?: string;
|
130
|
-
argsBase64?: string;
|
131
|
-
publicKey?: string;
|
132
|
-
keyType?: string;
|
133
|
-
}): Promise<any>;
|
134
|
-
/**
|
135
|
-
* View account information (convenience method)
|
136
|
-
*/
|
137
|
-
viewAccount(params: {
|
138
|
-
accountId: string;
|
139
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
140
|
-
blockId?: string | number;
|
141
|
-
}): Promise<any>;
|
142
|
-
/**
|
143
|
-
* View function call (convenience method)
|
144
|
-
*/
|
145
|
-
viewFunction(params: {
|
146
|
-
accountId: string;
|
147
|
-
methodName: string;
|
148
|
-
argsBase64?: string;
|
149
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
150
|
-
blockId?: string | number;
|
151
|
-
}): Promise<any>;
|
152
|
-
/**
|
153
|
-
* View access key (convenience method)
|
154
|
-
*/
|
155
|
-
viewAccessKey(params: {
|
156
|
-
accountId: string;
|
157
|
-
publicKey: string;
|
158
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
159
|
-
blockId?: string | number;
|
160
|
-
}): Promise<any>;
|
161
|
-
/**
|
162
|
-
* Get light client proof
|
163
|
-
*/
|
164
|
-
lightClientProof(params: {
|
165
|
-
type: string;
|
166
|
-
lightClientHead: string;
|
167
|
-
transactionHash?: string;
|
168
|
-
senderId?: string;
|
169
|
-
receiptId?: string;
|
170
|
-
}): Promise<any>;
|
171
|
-
/**
|
172
|
-
* Get state changes (experimental)
|
173
|
-
*/
|
174
|
-
experimentalChanges(params: {
|
175
|
-
changesType: string;
|
176
|
-
accountIds?: string[];
|
177
|
-
keyPrefixBase64?: string;
|
178
|
-
blockId?: string | number;
|
179
|
-
}): Promise<any>;
|
180
|
-
/**
|
181
|
-
* Get state changes in block (experimental)
|
182
|
-
*/
|
183
|
-
experimentalChangesInBlock(params: {
|
184
|
-
blockId: string | number;
|
185
|
-
}): Promise<any>;
|
186
|
-
/**
|
187
|
-
* Get ordered validators (experimental)
|
188
|
-
*/
|
189
|
-
experimentalValidatorsOrdered(params?: {
|
190
|
-
blockId?: string | number;
|
191
|
-
}): Promise<any>;
|
192
|
-
/**
|
193
|
-
* Get protocol configuration (experimental)
|
194
|
-
*/
|
195
|
-
experimentalProtocolConfig(params?: {
|
196
|
-
blockId?: string | number;
|
197
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
198
|
-
}): Promise<any>;
|
199
|
-
/**
|
200
|
-
* Get genesis configuration (experimental)
|
201
|
-
*/
|
202
|
-
experimentalGenesisConfig(): Promise<any>;
|
203
|
-
/**
|
204
|
-
* Get receipt information (experimental)
|
205
|
-
*/
|
206
|
-
experimentalReceipt(params: {
|
207
|
-
receiptId: string;
|
208
|
-
}): Promise<any>;
|
209
|
-
/**
|
210
|
-
* Get transaction status (experimental)
|
211
|
-
*/
|
212
|
-
experimentalTxStatus(params: {
|
213
|
-
txHash: string;
|
214
|
-
senderAccountId: string;
|
215
|
-
}): Promise<any>;
|
109
|
+
call<TParams = unknown, TResult = unknown>(method: RpcMethod, params?: TParams): Promise<TResult>;
|
110
|
+
}
|
111
|
+
interface NearRpcClient extends DynamicRpcMethods, ConvenienceMethods {
|
216
112
|
}
|
217
113
|
|
218
114
|
interface RpcRequest {
|
@@ -238,4 +134,4 @@ declare class NearRpcError extends Error {
|
|
238
134
|
constructor(code: number, message: string, data?: unknown | undefined);
|
239
135
|
}
|
240
136
|
|
241
|
-
export { type ClientConfig, JsonRpcClientError, type JsonRpcError, JsonRpcNetworkError, type JsonRpcRequest, type JsonRpcResponse, NearRpcClient, NearRpcError, type RpcError, type RpcRequest, type RpcResponse, NearRpcClient as default };
|
137
|
+
export { type ClientConfig, type CompleteClientInterface, type ConvenienceMethods, type DynamicRpcMethods, JsonRpcClientError, type JsonRpcError, JsonRpcNetworkError, type JsonRpcRequest, type JsonRpcResponse, NearRpcClient, NearRpcError, type RpcError, type RpcRequest, type RpcResponse, NearRpcClient as default };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,61 @@
|
|
1
|
-
|
1
|
+
import { RpcStateChangesInBlockByTypeRequest, RpcStateChangesInBlockResponse, RpcStateChangesInBlockRequest, RpcStateChangesInBlockByTypeResponse, RpcCongestionLevelRequest, RpcCongestionLevelResponse, GenesisConfigRequest, GenesisConfig, RpcLightClientBlockProofRequest, RpcLightClientBlockProofResponse, RpcLightClientExecutionProofRequest, RpcLightClientExecutionProofResponse, RpcMaintenanceWindowsRequest, EXPERIMENTALMaintenanceWindowsResponse, RpcProtocolConfigRequest, RpcProtocolConfigResponse, RpcReceiptRequest, RpcReceiptResponse, RpcSplitStorageInfoRequest, RpcSplitStorageInfoResponse, RpcTransactionStatusRequest, RpcTransactionResponse, RpcValidatorsOrderedRequest, EXPERIMENTALValidatorsOrderedResponse, RpcBlockRequest, RpcBlockResponse, RpcSendTransactionRequest, CryptoHash, RpcChunkRequest, RpcChunkResponse, RpcClientConfigRequest, RpcClientConfigResponse, RpcGasPriceRequest, RpcGasPriceResponse, RpcHealthRequest, RpcHealthResponse, RpcNetworkInfoRequest, RpcNetworkInfoResponse, RpcLightClientNextBlockRequest, RpcLightClientNextBlockResponse, RpcQueryRequest, RpcQueryResponse, RpcStatusRequest, RpcStatusResponse, RpcValidatorRequest, RpcValidatorResponse, AccountView, CallResult, AccessKeyView, RPC_METHODS } from '@near-js/jsonrpc-types';
|
2
|
+
export { JsonRpcRequestSchema, JsonRpcResponseSchema, RPC_METHODS } from '@near-js/jsonrpc-types';
|
2
3
|
|
4
|
+
interface DynamicRpcMethods {
|
5
|
+
experimentalChanges(params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
|
6
|
+
experimentalChangesInBlock(params?: RpcStateChangesInBlockRequest): Promise<RpcStateChangesInBlockByTypeResponse>;
|
7
|
+
experimentalCongestionLevel(params?: RpcCongestionLevelRequest): Promise<RpcCongestionLevelResponse>;
|
8
|
+
experimentalGenesisConfig(params?: GenesisConfigRequest): Promise<GenesisConfig>;
|
9
|
+
experimentalLightClientBlockProof(params?: RpcLightClientBlockProofRequest): Promise<RpcLightClientBlockProofResponse>;
|
10
|
+
experimentalLightClientProof(params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
|
11
|
+
experimentalMaintenanceWindows(params?: RpcMaintenanceWindowsRequest): Promise<EXPERIMENTALMaintenanceWindowsResponse>;
|
12
|
+
experimentalProtocolConfig(params?: RpcProtocolConfigRequest): Promise<RpcProtocolConfigResponse>;
|
13
|
+
experimentalReceipt(params?: RpcReceiptRequest): Promise<RpcReceiptResponse>;
|
14
|
+
experimentalSplitStorageInfo(params?: RpcSplitStorageInfoRequest): Promise<RpcSplitStorageInfoResponse>;
|
15
|
+
experimentalTxStatus(params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
|
16
|
+
experimentalValidatorsOrdered(params?: RpcValidatorsOrderedRequest): Promise<EXPERIMENTALValidatorsOrderedResponse>;
|
17
|
+
block(params?: RpcBlockRequest): Promise<RpcBlockResponse>;
|
18
|
+
broadcastTxAsync(params?: RpcSendTransactionRequest): Promise<CryptoHash>;
|
19
|
+
broadcastTxCommit(params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
|
20
|
+
changes(params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
|
21
|
+
chunk(params?: RpcChunkRequest): Promise<RpcChunkResponse>;
|
22
|
+
clientConfig(params?: RpcClientConfigRequest): Promise<RpcClientConfigResponse>;
|
23
|
+
gasPrice(params?: RpcGasPriceRequest): Promise<RpcGasPriceResponse>;
|
24
|
+
health(params?: RpcHealthRequest): Promise<RpcHealthResponse>;
|
25
|
+
lightClientProof(params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
|
26
|
+
networkInfo(params?: RpcNetworkInfoRequest): Promise<RpcNetworkInfoResponse>;
|
27
|
+
nextLightClientBlock(params?: RpcLightClientNextBlockRequest): Promise<RpcLightClientNextBlockResponse>;
|
28
|
+
query(params?: RpcQueryRequest): Promise<RpcQueryResponse>;
|
29
|
+
sendTx(params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
|
30
|
+
status(params?: RpcStatusRequest): Promise<RpcStatusResponse>;
|
31
|
+
tx(params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
|
32
|
+
validators(params?: RpcValidatorRequest): Promise<RpcValidatorResponse>;
|
33
|
+
}
|
34
|
+
interface ConvenienceMethods {
|
35
|
+
viewAccount(params: {
|
36
|
+
accountId: string;
|
37
|
+
finality?: 'final' | 'near-final' | 'optimistic';
|
38
|
+
blockId?: string | number;
|
39
|
+
}): Promise<AccountView>;
|
40
|
+
viewFunction(params: {
|
41
|
+
accountId: string;
|
42
|
+
methodName: string;
|
43
|
+
argsBase64?: string;
|
44
|
+
finality?: 'final' | 'near-final' | 'optimistic';
|
45
|
+
blockId?: string | number;
|
46
|
+
}): Promise<CallResult>;
|
47
|
+
viewAccessKey(params: {
|
48
|
+
accountId: string;
|
49
|
+
publicKey: string;
|
50
|
+
finality?: 'final' | 'near-final' | 'optimistic';
|
51
|
+
blockId?: string | number;
|
52
|
+
}): Promise<AccessKeyView>;
|
53
|
+
}
|
54
|
+
interface CompleteClientInterface extends DynamicRpcMethods, ConvenienceMethods {
|
55
|
+
call<TParams = unknown, TResult = unknown>(method: string, params?: TParams): Promise<TResult>;
|
56
|
+
}
|
57
|
+
|
58
|
+
type RpcMethod = (typeof RPC_METHODS)[number];
|
3
59
|
interface ClientConfig {
|
4
60
|
endpoint: string;
|
5
61
|
headers?: Record<string, string>;
|
@@ -33,6 +89,7 @@ declare class JsonRpcNetworkError extends Error {
|
|
33
89
|
originalError: Error;
|
34
90
|
constructor(message: string, originalError: Error);
|
35
91
|
}
|
92
|
+
|
36
93
|
declare class NearRpcClient {
|
37
94
|
private endpoint;
|
38
95
|
private headers;
|
@@ -47,172 +104,11 @@ declare class NearRpcClient {
|
|
47
104
|
private generateRequestId;
|
48
105
|
/**
|
49
106
|
* Make a raw JSON-RPC call
|
107
|
+
* This method is public to allow dynamic calls to any RPC method
|
50
108
|
*/
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
*/
|
55
|
-
status(): Promise<any>;
|
56
|
-
/**
|
57
|
-
* Get block information
|
58
|
-
*/
|
59
|
-
block(params?: {
|
60
|
-
blockId?: string | number;
|
61
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
62
|
-
}): Promise<any>;
|
63
|
-
/**
|
64
|
-
* Get current gas price
|
65
|
-
*/
|
66
|
-
gasPrice(params?: {
|
67
|
-
blockId?: string | number;
|
68
|
-
}): Promise<any>;
|
69
|
-
/**
|
70
|
-
* Get chunk information
|
71
|
-
*/
|
72
|
-
chunk(params: {
|
73
|
-
chunkId: string;
|
74
|
-
} | {
|
75
|
-
blockId: string | number;
|
76
|
-
shardId: number;
|
77
|
-
}): Promise<any>;
|
78
|
-
/**
|
79
|
-
* Health check
|
80
|
-
*/
|
81
|
-
health(): Promise<any>;
|
82
|
-
/**
|
83
|
-
* Get network information
|
84
|
-
*/
|
85
|
-
networkInfo(): Promise<any>;
|
86
|
-
/**
|
87
|
-
* Get current validators
|
88
|
-
*/
|
89
|
-
validators(params?: {
|
90
|
-
blockId?: string | number;
|
91
|
-
}): Promise<any>;
|
92
|
-
/**
|
93
|
-
* Get client configuration
|
94
|
-
*/
|
95
|
-
clientConfig(): Promise<any>;
|
96
|
-
/**
|
97
|
-
* Broadcast transaction asynchronously
|
98
|
-
*/
|
99
|
-
broadcastTxAsync(params: {
|
100
|
-
signedTxBase64: string;
|
101
|
-
}): Promise<any>;
|
102
|
-
/**
|
103
|
-
* Broadcast transaction and wait for commit
|
104
|
-
*/
|
105
|
-
broadcastTxCommit(params: {
|
106
|
-
signedTxBase64: string;
|
107
|
-
}): Promise<any>;
|
108
|
-
/**
|
109
|
-
* Send transaction
|
110
|
-
*/
|
111
|
-
sendTx(params: {
|
112
|
-
signedTxBase64: string;
|
113
|
-
}): Promise<any>;
|
114
|
-
/**
|
115
|
-
* Get transaction status
|
116
|
-
*/
|
117
|
-
tx(params: {
|
118
|
-
txHash: string;
|
119
|
-
senderAccountId: string;
|
120
|
-
}): Promise<any>;
|
121
|
-
/**
|
122
|
-
* Query account/contract state
|
123
|
-
*/
|
124
|
-
query(params: {
|
125
|
-
requestType: string;
|
126
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
127
|
-
blockId?: string | number;
|
128
|
-
accountId?: string;
|
129
|
-
methodName?: string;
|
130
|
-
argsBase64?: string;
|
131
|
-
publicKey?: string;
|
132
|
-
keyType?: string;
|
133
|
-
}): Promise<any>;
|
134
|
-
/**
|
135
|
-
* View account information (convenience method)
|
136
|
-
*/
|
137
|
-
viewAccount(params: {
|
138
|
-
accountId: string;
|
139
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
140
|
-
blockId?: string | number;
|
141
|
-
}): Promise<any>;
|
142
|
-
/**
|
143
|
-
* View function call (convenience method)
|
144
|
-
*/
|
145
|
-
viewFunction(params: {
|
146
|
-
accountId: string;
|
147
|
-
methodName: string;
|
148
|
-
argsBase64?: string;
|
149
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
150
|
-
blockId?: string | number;
|
151
|
-
}): Promise<any>;
|
152
|
-
/**
|
153
|
-
* View access key (convenience method)
|
154
|
-
*/
|
155
|
-
viewAccessKey(params: {
|
156
|
-
accountId: string;
|
157
|
-
publicKey: string;
|
158
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
159
|
-
blockId?: string | number;
|
160
|
-
}): Promise<any>;
|
161
|
-
/**
|
162
|
-
* Get light client proof
|
163
|
-
*/
|
164
|
-
lightClientProof(params: {
|
165
|
-
type: string;
|
166
|
-
lightClientHead: string;
|
167
|
-
transactionHash?: string;
|
168
|
-
senderId?: string;
|
169
|
-
receiptId?: string;
|
170
|
-
}): Promise<any>;
|
171
|
-
/**
|
172
|
-
* Get state changes (experimental)
|
173
|
-
*/
|
174
|
-
experimentalChanges(params: {
|
175
|
-
changesType: string;
|
176
|
-
accountIds?: string[];
|
177
|
-
keyPrefixBase64?: string;
|
178
|
-
blockId?: string | number;
|
179
|
-
}): Promise<any>;
|
180
|
-
/**
|
181
|
-
* Get state changes in block (experimental)
|
182
|
-
*/
|
183
|
-
experimentalChangesInBlock(params: {
|
184
|
-
blockId: string | number;
|
185
|
-
}): Promise<any>;
|
186
|
-
/**
|
187
|
-
* Get ordered validators (experimental)
|
188
|
-
*/
|
189
|
-
experimentalValidatorsOrdered(params?: {
|
190
|
-
blockId?: string | number;
|
191
|
-
}): Promise<any>;
|
192
|
-
/**
|
193
|
-
* Get protocol configuration (experimental)
|
194
|
-
*/
|
195
|
-
experimentalProtocolConfig(params?: {
|
196
|
-
blockId?: string | number;
|
197
|
-
finality?: 'final' | 'near-final' | 'optimistic';
|
198
|
-
}): Promise<any>;
|
199
|
-
/**
|
200
|
-
* Get genesis configuration (experimental)
|
201
|
-
*/
|
202
|
-
experimentalGenesisConfig(): Promise<any>;
|
203
|
-
/**
|
204
|
-
* Get receipt information (experimental)
|
205
|
-
*/
|
206
|
-
experimentalReceipt(params: {
|
207
|
-
receiptId: string;
|
208
|
-
}): Promise<any>;
|
209
|
-
/**
|
210
|
-
* Get transaction status (experimental)
|
211
|
-
*/
|
212
|
-
experimentalTxStatus(params: {
|
213
|
-
txHash: string;
|
214
|
-
senderAccountId: string;
|
215
|
-
}): Promise<any>;
|
109
|
+
call<TParams = unknown, TResult = unknown>(method: RpcMethod, params?: TParams): Promise<TResult>;
|
110
|
+
}
|
111
|
+
interface NearRpcClient extends DynamicRpcMethods, ConvenienceMethods {
|
216
112
|
}
|
217
113
|
|
218
114
|
interface RpcRequest {
|
@@ -238,4 +134,4 @@ declare class NearRpcError extends Error {
|
|
238
134
|
constructor(code: number, message: string, data?: unknown | undefined);
|
239
135
|
}
|
240
136
|
|
241
|
-
export { type ClientConfig, JsonRpcClientError, type JsonRpcError, JsonRpcNetworkError, type JsonRpcRequest, type JsonRpcResponse, NearRpcClient, NearRpcError, type RpcError, type RpcRequest, type RpcResponse, NearRpcClient as default };
|
137
|
+
export { type ClientConfig, type CompleteClientInterface, type ConvenienceMethods, type DynamicRpcMethods, JsonRpcClientError, type JsonRpcError, JsonRpcNetworkError, type JsonRpcRequest, type JsonRpcResponse, NearRpcClient, NearRpcError, type RpcError, type RpcRequest, type RpcResponse, NearRpcClient as default };
|
package/dist/index.js
CHANGED
@@ -22,9 +22,11 @@ var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
23
23
|
JsonRpcClientError: () => JsonRpcClientError,
|
24
24
|
JsonRpcNetworkError: () => JsonRpcNetworkError,
|
25
|
+
JsonRpcRequestSchema: () => import_jsonrpc_types2.JsonRpcRequestSchema,
|
26
|
+
JsonRpcResponseSchema: () => import_jsonrpc_types2.JsonRpcResponseSchema,
|
25
27
|
NearRpcClient: () => NearRpcClient,
|
26
28
|
NearRpcError: () => NearRpcError,
|
27
|
-
RPC_METHODS: () =>
|
29
|
+
RPC_METHODS: () => import_jsonrpc_types3.RPC_METHODS,
|
28
30
|
default: () => NearRpcClient
|
29
31
|
});
|
30
32
|
module.exports = __toCommonJS(index_exports);
|
@@ -115,6 +117,7 @@ var NearRpcClient = class {
|
|
115
117
|
}
|
116
118
|
/**
|
117
119
|
* Make a raw JSON-RPC call
|
120
|
+
* This method is public to allow dynamic calls to any RPC method
|
118
121
|
*/
|
119
122
|
async call(method, params) {
|
120
123
|
const requestId = this.generateRequestId();
|
@@ -187,162 +190,38 @@ var NearRpcClient = class {
|
|
187
190
|
lastError
|
188
191
|
);
|
189
192
|
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
*/
|
201
|
-
async block(params) {
|
202
|
-
return this.call("block", params);
|
203
|
-
}
|
204
|
-
/**
|
205
|
-
* Get current gas price
|
206
|
-
*/
|
207
|
-
async gasPrice(params) {
|
208
|
-
return this.call("gas_price", params);
|
209
|
-
}
|
210
|
-
/**
|
211
|
-
* Get chunk information
|
212
|
-
*/
|
213
|
-
async chunk(params) {
|
214
|
-
return this.call("chunk", params);
|
215
|
-
}
|
216
|
-
/**
|
217
|
-
* Health check
|
218
|
-
*/
|
219
|
-
async health() {
|
220
|
-
return this.call("health");
|
221
|
-
}
|
222
|
-
/**
|
223
|
-
* Get network information
|
224
|
-
*/
|
225
|
-
async networkInfo() {
|
226
|
-
return this.call("network_info");
|
227
|
-
}
|
228
|
-
/**
|
229
|
-
* Get current validators
|
230
|
-
*/
|
231
|
-
async validators(params) {
|
232
|
-
return this.call("validators", params);
|
233
|
-
}
|
234
|
-
/**
|
235
|
-
* Get client configuration
|
236
|
-
*/
|
237
|
-
async clientConfig() {
|
238
|
-
return this.call("client_config");
|
239
|
-
}
|
240
|
-
/**
|
241
|
-
* Broadcast transaction asynchronously
|
242
|
-
*/
|
243
|
-
async broadcastTxAsync(params) {
|
244
|
-
return this.call("broadcast_tx_async", params);
|
245
|
-
}
|
246
|
-
/**
|
247
|
-
* Broadcast transaction and wait for commit
|
248
|
-
*/
|
249
|
-
async broadcastTxCommit(params) {
|
250
|
-
return this.call("broadcast_tx_commit", params);
|
251
|
-
}
|
252
|
-
/**
|
253
|
-
* Send transaction
|
254
|
-
*/
|
255
|
-
async sendTx(params) {
|
256
|
-
return await this.call("send_tx", params);
|
257
|
-
}
|
258
|
-
/**
|
259
|
-
* Get transaction status
|
260
|
-
*/
|
261
|
-
async tx(params) {
|
262
|
-
return this.call("tx", params);
|
263
|
-
}
|
264
|
-
/**
|
265
|
-
* Query account/contract state
|
266
|
-
*/
|
267
|
-
async query(params) {
|
268
|
-
return this.call("query", params);
|
269
|
-
}
|
270
|
-
/**
|
271
|
-
* View account information (convenience method)
|
272
|
-
*/
|
273
|
-
async viewAccount(params) {
|
274
|
-
return this.query({
|
275
|
-
requestType: "view_account",
|
276
|
-
...params
|
277
|
-
});
|
278
|
-
}
|
279
|
-
/**
|
280
|
-
* View function call (convenience method)
|
281
|
-
*/
|
282
|
-
async viewFunction(params) {
|
283
|
-
return this.query({
|
284
|
-
requestType: "call_function",
|
285
|
-
...params
|
286
|
-
});
|
287
|
-
}
|
288
|
-
/**
|
289
|
-
* View access key (convenience method)
|
290
|
-
*/
|
291
|
-
async viewAccessKey(params) {
|
292
|
-
return this.query({
|
293
|
-
requestType: "view_access_key",
|
294
|
-
...params
|
295
|
-
});
|
296
|
-
}
|
297
|
-
/**
|
298
|
-
* Get light client proof
|
299
|
-
*/
|
300
|
-
async lightClientProof(params) {
|
301
|
-
return this.call("light_client_proof", params);
|
302
|
-
}
|
303
|
-
// Experimental methods
|
304
|
-
/**
|
305
|
-
* Get state changes (experimental)
|
306
|
-
*/
|
307
|
-
async experimentalChanges(params) {
|
308
|
-
return this.call("EXPERIMENTAL_changes", params);
|
309
|
-
}
|
310
|
-
/**
|
311
|
-
* Get state changes in block (experimental)
|
312
|
-
*/
|
313
|
-
async experimentalChangesInBlock(params) {
|
314
|
-
return this.call("EXPERIMENTAL_changes_in_block", params);
|
315
|
-
}
|
316
|
-
/**
|
317
|
-
* Get ordered validators (experimental)
|
318
|
-
*/
|
319
|
-
async experimentalValidatorsOrdered(params) {
|
320
|
-
return this.call("EXPERIMENTAL_validators_ordered", params);
|
321
|
-
}
|
322
|
-
/**
|
323
|
-
* Get protocol configuration (experimental)
|
324
|
-
*/
|
325
|
-
async experimentalProtocolConfig(params) {
|
326
|
-
return this.call("EXPERIMENTAL_protocol_config", params);
|
327
|
-
}
|
328
|
-
/**
|
329
|
-
* Get genesis configuration (experimental)
|
330
|
-
*/
|
331
|
-
async experimentalGenesisConfig() {
|
332
|
-
return this.call("EXPERIMENTAL_genesis_config");
|
333
|
-
}
|
334
|
-
/**
|
335
|
-
* Get receipt information (experimental)
|
336
|
-
*/
|
337
|
-
async experimentalReceipt(params) {
|
338
|
-
return this.call("EXPERIMENTAL_receipt", params);
|
339
|
-
}
|
340
|
-
/**
|
341
|
-
* Get transaction status (experimental)
|
342
|
-
*/
|
343
|
-
async experimentalTxStatus(params) {
|
344
|
-
return this.call("EXPERIMENTAL_tx_status", params);
|
193
|
+
};
|
194
|
+
import_jsonrpc_types.RPC_METHODS.forEach((method) => {
|
195
|
+
let methodName = method;
|
196
|
+
if (methodName.startsWith("EXPERIMENTAL_")) {
|
197
|
+
methodName = "experimental" + methodName.substring(13).replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^([a-z])/, (_, letter) => letter.toUpperCase());
|
198
|
+
} else {
|
199
|
+
methodName = methodName.replace(
|
200
|
+
/_([a-z])/g,
|
201
|
+
(_, letter) => letter.toUpperCase()
|
202
|
+
);
|
345
203
|
}
|
204
|
+
NearRpcClient.prototype[methodName] = function(params) {
|
205
|
+
return this.call(method, params);
|
206
|
+
};
|
207
|
+
});
|
208
|
+
NearRpcClient.prototype.viewAccount = function(params) {
|
209
|
+
return this.query({
|
210
|
+
requestType: "view_account",
|
211
|
+
...params
|
212
|
+
});
|
213
|
+
};
|
214
|
+
NearRpcClient.prototype.viewFunction = function(params) {
|
215
|
+
return this.query({
|
216
|
+
requestType: "call_function",
|
217
|
+
...params
|
218
|
+
});
|
219
|
+
};
|
220
|
+
NearRpcClient.prototype.viewAccessKey = function(params) {
|
221
|
+
return this.query({
|
222
|
+
requestType: "view_access_key",
|
223
|
+
...params
|
224
|
+
});
|
346
225
|
};
|
347
226
|
|
348
227
|
// src/types.ts
|
@@ -357,10 +236,13 @@ var NearRpcError = class extends Error {
|
|
357
236
|
|
358
237
|
// src/index.ts
|
359
238
|
var import_jsonrpc_types2 = require("@psalomo/jsonrpc-types");
|
239
|
+
var import_jsonrpc_types3 = require("@psalomo/jsonrpc-types");
|
360
240
|
// Annotate the CommonJS export names for ESM import in node:
|
361
241
|
0 && (module.exports = {
|
362
242
|
JsonRpcClientError,
|
363
243
|
JsonRpcNetworkError,
|
244
|
+
JsonRpcRequestSchema,
|
245
|
+
JsonRpcResponseSchema,
|
364
246
|
NearRpcClient,
|
365
247
|
NearRpcError,
|
366
248
|
RPC_METHODS
|
package/dist/index.mjs
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
// src/client.ts
|
2
2
|
import {
|
3
3
|
JsonRpcRequestSchema,
|
4
|
-
JsonRpcResponseSchema
|
4
|
+
JsonRpcResponseSchema,
|
5
|
+
RPC_METHODS
|
5
6
|
} from "@psalomo/jsonrpc-types";
|
6
7
|
var JsonRpcClientError = class extends Error {
|
7
8
|
constructor(message, code, data) {
|
@@ -87,6 +88,7 @@ var NearRpcClient = class {
|
|
87
88
|
}
|
88
89
|
/**
|
89
90
|
* Make a raw JSON-RPC call
|
91
|
+
* This method is public to allow dynamic calls to any RPC method
|
90
92
|
*/
|
91
93
|
async call(method, params) {
|
92
94
|
const requestId = this.generateRequestId();
|
@@ -159,162 +161,38 @@ var NearRpcClient = class {
|
|
159
161
|
lastError
|
160
162
|
);
|
161
163
|
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
*/
|
173
|
-
async block(params) {
|
174
|
-
return this.call("block", params);
|
175
|
-
}
|
176
|
-
/**
|
177
|
-
* Get current gas price
|
178
|
-
*/
|
179
|
-
async gasPrice(params) {
|
180
|
-
return this.call("gas_price", params);
|
181
|
-
}
|
182
|
-
/**
|
183
|
-
* Get chunk information
|
184
|
-
*/
|
185
|
-
async chunk(params) {
|
186
|
-
return this.call("chunk", params);
|
187
|
-
}
|
188
|
-
/**
|
189
|
-
* Health check
|
190
|
-
*/
|
191
|
-
async health() {
|
192
|
-
return this.call("health");
|
193
|
-
}
|
194
|
-
/**
|
195
|
-
* Get network information
|
196
|
-
*/
|
197
|
-
async networkInfo() {
|
198
|
-
return this.call("network_info");
|
199
|
-
}
|
200
|
-
/**
|
201
|
-
* Get current validators
|
202
|
-
*/
|
203
|
-
async validators(params) {
|
204
|
-
return this.call("validators", params);
|
205
|
-
}
|
206
|
-
/**
|
207
|
-
* Get client configuration
|
208
|
-
*/
|
209
|
-
async clientConfig() {
|
210
|
-
return this.call("client_config");
|
211
|
-
}
|
212
|
-
/**
|
213
|
-
* Broadcast transaction asynchronously
|
214
|
-
*/
|
215
|
-
async broadcastTxAsync(params) {
|
216
|
-
return this.call("broadcast_tx_async", params);
|
217
|
-
}
|
218
|
-
/**
|
219
|
-
* Broadcast transaction and wait for commit
|
220
|
-
*/
|
221
|
-
async broadcastTxCommit(params) {
|
222
|
-
return this.call("broadcast_tx_commit", params);
|
223
|
-
}
|
224
|
-
/**
|
225
|
-
* Send transaction
|
226
|
-
*/
|
227
|
-
async sendTx(params) {
|
228
|
-
return await this.call("send_tx", params);
|
229
|
-
}
|
230
|
-
/**
|
231
|
-
* Get transaction status
|
232
|
-
*/
|
233
|
-
async tx(params) {
|
234
|
-
return this.call("tx", params);
|
235
|
-
}
|
236
|
-
/**
|
237
|
-
* Query account/contract state
|
238
|
-
*/
|
239
|
-
async query(params) {
|
240
|
-
return this.call("query", params);
|
241
|
-
}
|
242
|
-
/**
|
243
|
-
* View account information (convenience method)
|
244
|
-
*/
|
245
|
-
async viewAccount(params) {
|
246
|
-
return this.query({
|
247
|
-
requestType: "view_account",
|
248
|
-
...params
|
249
|
-
});
|
250
|
-
}
|
251
|
-
/**
|
252
|
-
* View function call (convenience method)
|
253
|
-
*/
|
254
|
-
async viewFunction(params) {
|
255
|
-
return this.query({
|
256
|
-
requestType: "call_function",
|
257
|
-
...params
|
258
|
-
});
|
259
|
-
}
|
260
|
-
/**
|
261
|
-
* View access key (convenience method)
|
262
|
-
*/
|
263
|
-
async viewAccessKey(params) {
|
264
|
-
return this.query({
|
265
|
-
requestType: "view_access_key",
|
266
|
-
...params
|
267
|
-
});
|
268
|
-
}
|
269
|
-
/**
|
270
|
-
* Get light client proof
|
271
|
-
*/
|
272
|
-
async lightClientProof(params) {
|
273
|
-
return this.call("light_client_proof", params);
|
274
|
-
}
|
275
|
-
// Experimental methods
|
276
|
-
/**
|
277
|
-
* Get state changes (experimental)
|
278
|
-
*/
|
279
|
-
async experimentalChanges(params) {
|
280
|
-
return this.call("EXPERIMENTAL_changes", params);
|
281
|
-
}
|
282
|
-
/**
|
283
|
-
* Get state changes in block (experimental)
|
284
|
-
*/
|
285
|
-
async experimentalChangesInBlock(params) {
|
286
|
-
return this.call("EXPERIMENTAL_changes_in_block", params);
|
287
|
-
}
|
288
|
-
/**
|
289
|
-
* Get ordered validators (experimental)
|
290
|
-
*/
|
291
|
-
async experimentalValidatorsOrdered(params) {
|
292
|
-
return this.call("EXPERIMENTAL_validators_ordered", params);
|
293
|
-
}
|
294
|
-
/**
|
295
|
-
* Get protocol configuration (experimental)
|
296
|
-
*/
|
297
|
-
async experimentalProtocolConfig(params) {
|
298
|
-
return this.call("EXPERIMENTAL_protocol_config", params);
|
299
|
-
}
|
300
|
-
/**
|
301
|
-
* Get genesis configuration (experimental)
|
302
|
-
*/
|
303
|
-
async experimentalGenesisConfig() {
|
304
|
-
return this.call("EXPERIMENTAL_genesis_config");
|
305
|
-
}
|
306
|
-
/**
|
307
|
-
* Get receipt information (experimental)
|
308
|
-
*/
|
309
|
-
async experimentalReceipt(params) {
|
310
|
-
return this.call("EXPERIMENTAL_receipt", params);
|
311
|
-
}
|
312
|
-
/**
|
313
|
-
* Get transaction status (experimental)
|
314
|
-
*/
|
315
|
-
async experimentalTxStatus(params) {
|
316
|
-
return this.call("EXPERIMENTAL_tx_status", params);
|
164
|
+
};
|
165
|
+
RPC_METHODS.forEach((method) => {
|
166
|
+
let methodName = method;
|
167
|
+
if (methodName.startsWith("EXPERIMENTAL_")) {
|
168
|
+
methodName = "experimental" + methodName.substring(13).replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^([a-z])/, (_, letter) => letter.toUpperCase());
|
169
|
+
} else {
|
170
|
+
methodName = methodName.replace(
|
171
|
+
/_([a-z])/g,
|
172
|
+
(_, letter) => letter.toUpperCase()
|
173
|
+
);
|
317
174
|
}
|
175
|
+
NearRpcClient.prototype[methodName] = function(params) {
|
176
|
+
return this.call(method, params);
|
177
|
+
};
|
178
|
+
});
|
179
|
+
NearRpcClient.prototype.viewAccount = function(params) {
|
180
|
+
return this.query({
|
181
|
+
requestType: "view_account",
|
182
|
+
...params
|
183
|
+
});
|
184
|
+
};
|
185
|
+
NearRpcClient.prototype.viewFunction = function(params) {
|
186
|
+
return this.query({
|
187
|
+
requestType: "call_function",
|
188
|
+
...params
|
189
|
+
});
|
190
|
+
};
|
191
|
+
NearRpcClient.prototype.viewAccessKey = function(params) {
|
192
|
+
return this.query({
|
193
|
+
requestType: "view_access_key",
|
194
|
+
...params
|
195
|
+
});
|
318
196
|
};
|
319
197
|
|
320
198
|
// src/types.ts
|
@@ -328,10 +206,16 @@ var NearRpcError = class extends Error {
|
|
328
206
|
};
|
329
207
|
|
330
208
|
// src/index.ts
|
209
|
+
import {
|
210
|
+
JsonRpcRequestSchema as JsonRpcRequestSchema2,
|
211
|
+
JsonRpcResponseSchema as JsonRpcResponseSchema2
|
212
|
+
} from "@psalomo/jsonrpc-types";
|
331
213
|
import { RPC_METHODS as RPC_METHODS2 } from "@psalomo/jsonrpc-types";
|
332
214
|
export {
|
333
215
|
JsonRpcClientError,
|
334
216
|
JsonRpcNetworkError,
|
217
|
+
JsonRpcRequestSchema2 as JsonRpcRequestSchema,
|
218
|
+
JsonRpcResponseSchema2 as JsonRpcResponseSchema,
|
335
219
|
NearRpcClient,
|
336
220
|
NearRpcError,
|
337
221
|
RPC_METHODS2 as RPC_METHODS,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@psalomo/jsonrpc-client",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"description": "TypeScript client for NEAR Protocol JSON-RPC API",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.mjs",
|
@@ -16,13 +16,15 @@
|
|
16
16
|
"dist"
|
17
17
|
],
|
18
18
|
"scripts": {
|
19
|
+
"prebuild": "cd ../../tools/codegen && npx tsx generate-client-interface.ts",
|
19
20
|
"build": "tsup",
|
20
21
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
21
22
|
"clean": "rm -rf dist",
|
22
23
|
"typecheck": "tsc --noEmit",
|
23
24
|
"lint": "prettier --check 'src/**/*.{ts,js}' '*.{ts,js}'",
|
24
25
|
"format": "prettier --write 'src/**/*.{ts,js}' '*.{ts,js}'",
|
25
|
-
"test": "vitest",
|
26
|
+
"test": "vitest run",
|
27
|
+
"test:watch": "vitest",
|
26
28
|
"test:coverage": "vitest run --coverage"
|
27
29
|
},
|
28
30
|
"dependencies": {
|