@elsoul/erpc-sdk 0.4.0 → 0.6.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 +30 -3
- package/dist/index.cjs +158 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +195 -1
- package/dist/index.d.ts +195 -1
- package/dist/index.js +152 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# `@elsoul/erpc-sdk`
|
|
2
2
|
|
|
3
3
|
Official type-safe TypeScript client for [ERPC](https://erpc.global). Use one
|
|
4
|
-
client and one API key for Solana, Ethereum,
|
|
5
|
-
and validator data, analytics, subscriptions, and account
|
|
4
|
+
client and one API key for Solana, Ethereum, Avalanche C/P/X chains, price data,
|
|
5
|
+
indexed data, leader and validator data, analytics, subscriptions, and account
|
|
6
|
+
information.
|
|
6
7
|
|
|
7
8
|
## Install
|
|
8
9
|
|
|
@@ -26,8 +27,9 @@ const erpc = createErpcClient({ apiKey })
|
|
|
26
27
|
|
|
27
28
|
const slot = await erpc.solana.rpc.getSlot().send()
|
|
28
29
|
const chainId = await erpc.ethereum.rpc.eth_chainId().send()
|
|
30
|
+
const avalancheChainId = await erpc.avalanche.rpc.eth_chainId().send()
|
|
29
31
|
|
|
30
|
-
console.log({ slot, chainId })
|
|
32
|
+
console.log({ slot, chainId, avalancheChainId })
|
|
31
33
|
erpc.close()
|
|
32
34
|
```
|
|
33
35
|
|
|
@@ -46,10 +48,25 @@ network request.
|
|
|
46
48
|
| `erpc.solana.subscriptions` | Enhanced WebSocket subscriptions |
|
|
47
49
|
| `erpc.ethereum.rpc` | Ethereum JSON-RPC |
|
|
48
50
|
| `erpc.ethereum.subscriptions` | Ethereum WebSocket subscriptions |
|
|
51
|
+
| `erpc.avalanche.rpc` | Avalanche C-Chain EVM-compatible JSON-RPC |
|
|
52
|
+
| `erpc.avalanche.subscriptions` | Avalanche C-Chain WebSocket subscriptions |
|
|
53
|
+
| `erpc.avalanche.avax` | C-Chain AVAX atomic transaction API |
|
|
54
|
+
| `erpc.avalanche.xChain` | X-Chain API |
|
|
55
|
+
| `erpc.avalanche.pChain` | P-Chain API |
|
|
56
|
+
| `erpc.avalanche.proposerVm` | P-Chain proposer VM API |
|
|
57
|
+
| `erpc.avalanche.info` | Network upgrade information |
|
|
58
|
+
| `erpc.avalanche.index` | C/P/X block and X transaction indexes |
|
|
49
59
|
| `erpc.price` | Price metadata, updates, and streams |
|
|
50
60
|
| `erpc.account` | ERPC token balance |
|
|
51
61
|
| `erpc.usage` | Masked monthly API-key usage |
|
|
52
62
|
|
|
63
|
+
`avalancheEndpoint` defaults to `https://ava-rpc.erpc.global` and can be
|
|
64
|
+
overridden independently from the shared `endpoint` option. The SDK uses its
|
|
65
|
+
`/ava` HTTP route and `/ava-ws` WebSocket route. Native C/P/X methods use named
|
|
66
|
+
parameters; Index calls are routed to the required explicit chain/container
|
|
67
|
+
path. Native and Index batches are rejected locally. Use `raw` with an exact
|
|
68
|
+
wire method name for forward compatibility.
|
|
69
|
+
|
|
53
70
|
## Examples
|
|
54
71
|
|
|
55
72
|
```ts
|
|
@@ -59,6 +76,16 @@ const block = await erpc.ethereum.rpc
|
|
|
59
76
|
.eth_getBlockByNumber('latest', false)
|
|
60
77
|
.send()
|
|
61
78
|
|
|
79
|
+
const avalancheBlock = await erpc.avalanche.rpc
|
|
80
|
+
.eth_getBlockByNumber('latest', false)
|
|
81
|
+
.send()
|
|
82
|
+
|
|
83
|
+
const pChainHeight = await erpc.avalanche.pChain.getHeight().send()
|
|
84
|
+
const xChainHeight = await erpc.avalanche.xChain.getHeight().send()
|
|
85
|
+
const indexedTransaction = await erpc.avalanche.index.xChainTransactions
|
|
86
|
+
.getContainerByID({ id: transactionId })
|
|
87
|
+
.send()
|
|
88
|
+
|
|
62
89
|
const prices = await erpc.price.getLatestPriceUpdates({
|
|
63
90
|
ids: [feedId],
|
|
64
91
|
parsed: true,
|
package/dist/index.cjs
CHANGED
|
@@ -316,6 +316,7 @@ var CloudCatalogClient = class {
|
|
|
316
316
|
|
|
317
317
|
// src/config.ts
|
|
318
318
|
var DEFAULT_ENDPOINT = "https://edge.erpc.global";
|
|
319
|
+
var DEFAULT_AVALANCHE_ENDPOINT = "https://ava-rpc.erpc.global";
|
|
319
320
|
var DEFAULT_ACCOUNT_ENDPOINT = "https://solana-rpc.erpc.global";
|
|
320
321
|
var DEFAULT_USER_ENDPOINT = "https://user-api.erpc.global";
|
|
321
322
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
@@ -332,10 +333,14 @@ var resolveConfig = (config) => {
|
|
|
332
333
|
const apiKey = config.apiKey.trim();
|
|
333
334
|
if (!apiKey) throw new ErpcConfigError("apiKey must not be empty");
|
|
334
335
|
let endpoint;
|
|
336
|
+
let avalancheEndpoint;
|
|
335
337
|
let accountEndpoint;
|
|
336
338
|
let userEndpoint;
|
|
337
339
|
try {
|
|
338
340
|
endpoint = new URL(config.endpoint ?? DEFAULT_ENDPOINT);
|
|
341
|
+
avalancheEndpoint = new URL(
|
|
342
|
+
config.avalancheEndpoint ?? DEFAULT_AVALANCHE_ENDPOINT
|
|
343
|
+
);
|
|
339
344
|
accountEndpoint = new URL(
|
|
340
345
|
config.accountEndpoint ?? DEFAULT_ACCOUNT_ENDPOINT
|
|
341
346
|
);
|
|
@@ -346,6 +351,9 @@ var resolveConfig = (config) => {
|
|
|
346
351
|
if (endpoint.protocol !== "https:" && endpoint.protocol !== "http:") {
|
|
347
352
|
throw new ErpcConfigError("endpoint must use HTTP or HTTPS");
|
|
348
353
|
}
|
|
354
|
+
if (avalancheEndpoint.protocol !== "https:" && avalancheEndpoint.protocol !== "http:") {
|
|
355
|
+
throw new ErpcConfigError("avalancheEndpoint must use HTTP or HTTPS");
|
|
356
|
+
}
|
|
349
357
|
if (accountEndpoint.protocol !== "https:" && accountEndpoint.protocol !== "http:") {
|
|
350
358
|
throw new ErpcConfigError("accountEndpoint must use HTTP or HTTPS");
|
|
351
359
|
}
|
|
@@ -355,6 +363,9 @@ var resolveConfig = (config) => {
|
|
|
355
363
|
endpoint.search = "";
|
|
356
364
|
endpoint.hash = "";
|
|
357
365
|
endpoint.pathname = endpoint.pathname.replace(/\/+$/, "") || "/";
|
|
366
|
+
avalancheEndpoint.search = "";
|
|
367
|
+
avalancheEndpoint.hash = "";
|
|
368
|
+
avalancheEndpoint.pathname = avalancheEndpoint.pathname.replace(/\/+$/, "") || "/";
|
|
358
369
|
accountEndpoint.search = "";
|
|
359
370
|
accountEndpoint.hash = "";
|
|
360
371
|
accountEndpoint.pathname = accountEndpoint.pathname.replace(/\/+$/, "") || "/";
|
|
@@ -368,6 +379,7 @@ var resolveConfig = (config) => {
|
|
|
368
379
|
return {
|
|
369
380
|
accountEndpoint,
|
|
370
381
|
apiKey,
|
|
382
|
+
avalancheEndpoint,
|
|
371
383
|
endpoint,
|
|
372
384
|
fetch: requireFetch(config.fetch),
|
|
373
385
|
headers: config.headers ?? {},
|
|
@@ -529,10 +541,14 @@ var methodParams = (mode, args) => {
|
|
|
529
541
|
return args[0];
|
|
530
542
|
};
|
|
531
543
|
var createRpcNamespace = (config) => {
|
|
544
|
+
const wireMethod = (method) => config.methodPrefix === void 0 ? method : `${config.methodPrefix}.${method}`;
|
|
532
545
|
const base = {
|
|
533
546
|
endpoint: config.transport.endpoint,
|
|
534
547
|
batch: (calls) => {
|
|
535
|
-
const wireCalls = calls
|
|
548
|
+
const wireCalls = calls.map((call) => ({
|
|
549
|
+
...call,
|
|
550
|
+
method: wireMethod(call.method)
|
|
551
|
+
}));
|
|
536
552
|
config.validateBatch?.(wireCalls);
|
|
537
553
|
return new PendingRpcBatchRequest(
|
|
538
554
|
(options) => config.transport.batch(
|
|
@@ -546,7 +562,7 @@ var createRpcNamespace = (config) => {
|
|
|
546
562
|
),
|
|
547
563
|
request: (method, ...params) => new PendingRpcRequest(
|
|
548
564
|
(options) => config.transport.request(
|
|
549
|
-
method,
|
|
565
|
+
wireMethod(method),
|
|
550
566
|
params[0],
|
|
551
567
|
options
|
|
552
568
|
)
|
|
@@ -560,7 +576,7 @@ var createRpcNamespace = (config) => {
|
|
|
560
576
|
if (property === "then") return void 0;
|
|
561
577
|
return (...args) => new PendingRpcRequest(
|
|
562
578
|
(options) => config.transport.request(
|
|
563
|
-
property,
|
|
579
|
+
wireMethod(property),
|
|
564
580
|
methodParams(config.parameterMode, args),
|
|
565
581
|
options
|
|
566
582
|
)
|
|
@@ -636,6 +652,110 @@ var createEthereumClient = (transport) => ({
|
|
|
636
652
|
})
|
|
637
653
|
});
|
|
638
654
|
|
|
655
|
+
// src/rpc/avalanche.ts
|
|
656
|
+
var AVALANCHE_AVAX_METHODS = [
|
|
657
|
+
"avax.getAtomicTx",
|
|
658
|
+
"avax.getAtomicTxStatus",
|
|
659
|
+
"avax.getUTXOs",
|
|
660
|
+
"avax.issueTx"
|
|
661
|
+
];
|
|
662
|
+
var AVALANCHE_X_CHAIN_METHODS = [
|
|
663
|
+
"avm.buildGenesis",
|
|
664
|
+
"avm.getAllBalances",
|
|
665
|
+
"avm.getAssetDescription",
|
|
666
|
+
"avm.getBalance",
|
|
667
|
+
"avm.getBlockByHeight",
|
|
668
|
+
"avm.getHeight",
|
|
669
|
+
"avm.getTx",
|
|
670
|
+
"avm.getTxFee",
|
|
671
|
+
"avm.getTxStatus",
|
|
672
|
+
"avm.getUTXOs",
|
|
673
|
+
"avm.issueTx"
|
|
674
|
+
];
|
|
675
|
+
var AVALANCHE_P_CHAIN_METHODS = [
|
|
676
|
+
"platform.getAllValidatorsAt",
|
|
677
|
+
"platform.getBalance",
|
|
678
|
+
"platform.getBlockchainStatus",
|
|
679
|
+
"platform.getBlockchains",
|
|
680
|
+
"platform.getCurrentSupply",
|
|
681
|
+
"platform.getCurrentValidators",
|
|
682
|
+
"platform.getFeeConfig",
|
|
683
|
+
"platform.getFeeState",
|
|
684
|
+
"platform.getHeight",
|
|
685
|
+
"platform.getMinStake",
|
|
686
|
+
"platform.getRewardUTXOs",
|
|
687
|
+
"platform.getStake",
|
|
688
|
+
"platform.getStakingAssetID",
|
|
689
|
+
"platform.getSubnets",
|
|
690
|
+
"platform.getTimestamp",
|
|
691
|
+
"platform.getTotalStake",
|
|
692
|
+
"platform.getTx",
|
|
693
|
+
"platform.getTxStatus",
|
|
694
|
+
"platform.getUTXOs",
|
|
695
|
+
"platform.getValidatorFeeConfig",
|
|
696
|
+
"platform.getValidatorFeeState",
|
|
697
|
+
"platform.getValidatorsAt",
|
|
698
|
+
"platform.issueTx",
|
|
699
|
+
"platform.sampleValidators",
|
|
700
|
+
"platform.validatedBy",
|
|
701
|
+
"platform.validates"
|
|
702
|
+
];
|
|
703
|
+
var AVALANCHE_PROPOSER_VM_METHODS = [
|
|
704
|
+
"proposervm.getCurrentEpoch",
|
|
705
|
+
"proposervm.getProposedHeight"
|
|
706
|
+
];
|
|
707
|
+
var AVALANCHE_INFO_METHODS = ["info.upgrades"];
|
|
708
|
+
var AVALANCHE_INDEX_METHODS = [
|
|
709
|
+
"index.getContainerByID",
|
|
710
|
+
"index.getContainerByIndex",
|
|
711
|
+
"index.getContainerRange",
|
|
712
|
+
"index.getIndex",
|
|
713
|
+
"index.getLastAccepted",
|
|
714
|
+
"index.isAccepted"
|
|
715
|
+
];
|
|
716
|
+
var rejectNativeBatch = (calls) => {
|
|
717
|
+
if (calls.length > 0) {
|
|
718
|
+
throw new ErpcBatchPolicyError(
|
|
719
|
+
"Avalanche native RPC methods do not support batching"
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
var nativeNamespace = (transport, methodPrefix) => createRpcNamespace({
|
|
724
|
+
methodPrefix,
|
|
725
|
+
parameterMode: "named",
|
|
726
|
+
transport,
|
|
727
|
+
validateBatch: rejectNativeBatch
|
|
728
|
+
});
|
|
729
|
+
var createAvalancheClient = (transport, indexTransports) => ({
|
|
730
|
+
...createEthereumClient(transport),
|
|
731
|
+
avax: nativeNamespace(transport, "avax"),
|
|
732
|
+
xChain: nativeNamespace(transport, "avm"),
|
|
733
|
+
pChain: nativeNamespace(transport, "platform"),
|
|
734
|
+
proposerVm: nativeNamespace(
|
|
735
|
+
transport,
|
|
736
|
+
"proposervm"
|
|
737
|
+
),
|
|
738
|
+
info: nativeNamespace(transport, "info"),
|
|
739
|
+
index: {
|
|
740
|
+
cChainBlocks: nativeNamespace(
|
|
741
|
+
indexTransports.cChainBlocks,
|
|
742
|
+
"index"
|
|
743
|
+
),
|
|
744
|
+
pChainBlocks: nativeNamespace(
|
|
745
|
+
indexTransports.pChainBlocks,
|
|
746
|
+
"index"
|
|
747
|
+
),
|
|
748
|
+
xChainBlocks: nativeNamespace(
|
|
749
|
+
indexTransports.xChainBlocks,
|
|
750
|
+
"index"
|
|
751
|
+
),
|
|
752
|
+
xChainTransactions: nativeNamespace(
|
|
753
|
+
indexTransports.xChainTransactions,
|
|
754
|
+
"index"
|
|
755
|
+
)
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
|
|
639
759
|
// src/rpc/solana.ts
|
|
640
760
|
var SOLANA_RPC_METHODS = [
|
|
641
761
|
"getAccountInfo",
|
|
@@ -1394,6 +1514,14 @@ var createErpcClient = (config) => {
|
|
|
1394
1514
|
...sharedTransport,
|
|
1395
1515
|
endpoint: ethereumEndpoint
|
|
1396
1516
|
});
|
|
1517
|
+
const avalancheTransport = new HttpJsonRpcTransport({
|
|
1518
|
+
...sharedTransport,
|
|
1519
|
+
endpoint: endpointWithPath(resolved.avalancheEndpoint, "/ava")
|
|
1520
|
+
});
|
|
1521
|
+
const avalancheIndexTransport = (path) => new HttpJsonRpcTransport({
|
|
1522
|
+
...sharedTransport,
|
|
1523
|
+
endpoint: endpointWithPath(resolved.avalancheEndpoint, path)
|
|
1524
|
+
});
|
|
1397
1525
|
const solanaWebSocket = new WebSocketJsonRpcTransport({
|
|
1398
1526
|
endpoint: websocketUrl(resolved.endpoint, resolved.apiKey),
|
|
1399
1527
|
timeoutMs: resolved.timeoutMs,
|
|
@@ -1404,6 +1532,15 @@ var createErpcClient = (config) => {
|
|
|
1404
1532
|
timeoutMs: resolved.timeoutMs,
|
|
1405
1533
|
...resolved.webSocket === void 0 ? {} : { webSocket: resolved.webSocket }
|
|
1406
1534
|
});
|
|
1535
|
+
const avalancheWebSocket = new WebSocketJsonRpcTransport({
|
|
1536
|
+
endpoint: websocketUrl(
|
|
1537
|
+
resolved.avalancheEndpoint,
|
|
1538
|
+
resolved.apiKey,
|
|
1539
|
+
"/ava-ws"
|
|
1540
|
+
),
|
|
1541
|
+
timeoutMs: resolved.timeoutMs,
|
|
1542
|
+
...resolved.webSocket === void 0 ? {} : { webSocket: resolved.webSocket }
|
|
1543
|
+
});
|
|
1407
1544
|
const priceTransport = new RestTransport({
|
|
1408
1545
|
...sharedTransport,
|
|
1409
1546
|
endpoint: resolved.endpoint
|
|
@@ -1424,15 +1561,26 @@ var createErpcClient = (config) => {
|
|
|
1424
1561
|
...createEthereumClient(ethereumTransport),
|
|
1425
1562
|
subscriptions: new EthereumSubscriptions(ethereumWebSocket)
|
|
1426
1563
|
};
|
|
1564
|
+
const avalanche = {
|
|
1565
|
+
...createAvalancheClient(avalancheTransport, {
|
|
1566
|
+
cChainBlocks: avalancheIndexTransport("/ava/ext/index/C/block"),
|
|
1567
|
+
pChainBlocks: avalancheIndexTransport("/ava/ext/index/P/block"),
|
|
1568
|
+
xChainBlocks: avalancheIndexTransport("/ava/ext/index/X/block"),
|
|
1569
|
+
xChainTransactions: avalancheIndexTransport("/ava/ext/index/X/tx")
|
|
1570
|
+
}),
|
|
1571
|
+
subscriptions: new EthereumSubscriptions(avalancheWebSocket)
|
|
1572
|
+
};
|
|
1427
1573
|
return {
|
|
1428
1574
|
solana,
|
|
1429
1575
|
ethereum,
|
|
1576
|
+
avalanche,
|
|
1430
1577
|
price: new PriceClient(priceTransport),
|
|
1431
1578
|
account: new AccountClient(accountTransport),
|
|
1432
1579
|
usage: new UsageClient(userTransport),
|
|
1433
1580
|
close: () => {
|
|
1434
1581
|
solana.subscriptions.close();
|
|
1435
1582
|
ethereum.subscriptions.close();
|
|
1583
|
+
avalanche.subscriptions.close();
|
|
1436
1584
|
}
|
|
1437
1585
|
};
|
|
1438
1586
|
};
|
|
@@ -1653,11 +1801,18 @@ var createErpcCloudClient = (config) => {
|
|
|
1653
1801
|
};
|
|
1654
1802
|
};
|
|
1655
1803
|
|
|
1804
|
+
exports.AVALANCHE_AVAX_METHODS = AVALANCHE_AVAX_METHODS;
|
|
1805
|
+
exports.AVALANCHE_INDEX_METHODS = AVALANCHE_INDEX_METHODS;
|
|
1806
|
+
exports.AVALANCHE_INFO_METHODS = AVALANCHE_INFO_METHODS;
|
|
1807
|
+
exports.AVALANCHE_PROPOSER_VM_METHODS = AVALANCHE_PROPOSER_VM_METHODS;
|
|
1808
|
+
exports.AVALANCHE_P_CHAIN_METHODS = AVALANCHE_P_CHAIN_METHODS;
|
|
1809
|
+
exports.AVALANCHE_X_CHAIN_METHODS = AVALANCHE_X_CHAIN_METHODS;
|
|
1656
1810
|
exports.AccountClient = AccountClient;
|
|
1657
1811
|
exports.CloudCatalogClient = CloudCatalogClient;
|
|
1658
1812
|
exports.CloudCreditClient = CloudCreditClient;
|
|
1659
1813
|
exports.CloudResourcesClient = CloudResourcesClient;
|
|
1660
1814
|
exports.DEFAULT_ACCOUNT_ENDPOINT = DEFAULT_ACCOUNT_ENDPOINT;
|
|
1815
|
+
exports.DEFAULT_AVALANCHE_ENDPOINT = DEFAULT_AVALANCHE_ENDPOINT;
|
|
1661
1816
|
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
1662
1817
|
exports.DEFAULT_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;
|
|
1663
1818
|
exports.DEFAULT_USER_ENDPOINT = DEFAULT_USER_ENDPOINT;
|