@elsoul/erpc-sdk 0.5.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 +17 -4
- package/dist/index.cjs +127 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +192 -2
- package/dist/index.d.ts +192 -2
- package/dist/index.js +122 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, Avalanche C
|
|
4
|
+
client and one API key for Solana, Ethereum, Avalanche C/P/X chains, price data,
|
|
5
5
|
indexed data, leader and validator data, analytics, subscriptions, and account
|
|
6
6
|
information.
|
|
7
7
|
|
|
@@ -50,15 +50,22 @@ network request.
|
|
|
50
50
|
| `erpc.ethereum.subscriptions` | Ethereum WebSocket subscriptions |
|
|
51
51
|
| `erpc.avalanche.rpc` | Avalanche C-Chain EVM-compatible JSON-RPC |
|
|
52
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 |
|
|
53
59
|
| `erpc.price` | Price metadata, updates, and streams |
|
|
54
60
|
| `erpc.account` | ERPC token balance |
|
|
55
61
|
| `erpc.usage` | Masked monthly API-key usage |
|
|
56
62
|
|
|
57
63
|
`avalancheEndpoint` defaults to `https://ava-rpc.erpc.global` and can be
|
|
58
64
|
overridden independently from the shared `endpoint` option. The SDK uses its
|
|
59
|
-
`/ava` HTTP route and `/ava-ws` WebSocket route.
|
|
60
|
-
|
|
61
|
-
|
|
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.
|
|
62
69
|
|
|
63
70
|
## Examples
|
|
64
71
|
|
|
@@ -73,6 +80,12 @@ const avalancheBlock = await erpc.avalanche.rpc
|
|
|
73
80
|
.eth_getBlockByNumber('latest', false)
|
|
74
81
|
.send()
|
|
75
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
|
+
|
|
76
89
|
const prices = await erpc.price.getLatestPriceUpdates({
|
|
77
90
|
ids: [feedId],
|
|
78
91
|
parsed: true,
|
package/dist/index.cjs
CHANGED
|
@@ -541,10 +541,14 @@ var methodParams = (mode, args) => {
|
|
|
541
541
|
return args[0];
|
|
542
542
|
};
|
|
543
543
|
var createRpcNamespace = (config) => {
|
|
544
|
+
const wireMethod = (method) => config.methodPrefix === void 0 ? method : `${config.methodPrefix}.${method}`;
|
|
544
545
|
const base = {
|
|
545
546
|
endpoint: config.transport.endpoint,
|
|
546
547
|
batch: (calls) => {
|
|
547
|
-
const wireCalls = calls
|
|
548
|
+
const wireCalls = calls.map((call) => ({
|
|
549
|
+
...call,
|
|
550
|
+
method: wireMethod(call.method)
|
|
551
|
+
}));
|
|
548
552
|
config.validateBatch?.(wireCalls);
|
|
549
553
|
return new PendingRpcBatchRequest(
|
|
550
554
|
(options) => config.transport.batch(
|
|
@@ -558,7 +562,7 @@ var createRpcNamespace = (config) => {
|
|
|
558
562
|
),
|
|
559
563
|
request: (method, ...params) => new PendingRpcRequest(
|
|
560
564
|
(options) => config.transport.request(
|
|
561
|
-
method,
|
|
565
|
+
wireMethod(method),
|
|
562
566
|
params[0],
|
|
563
567
|
options
|
|
564
568
|
)
|
|
@@ -572,7 +576,7 @@ var createRpcNamespace = (config) => {
|
|
|
572
576
|
if (property === "then") return void 0;
|
|
573
577
|
return (...args) => new PendingRpcRequest(
|
|
574
578
|
(options) => config.transport.request(
|
|
575
|
-
property,
|
|
579
|
+
wireMethod(property),
|
|
576
580
|
methodParams(config.parameterMode, args),
|
|
577
581
|
options
|
|
578
582
|
)
|
|
@@ -648,6 +652,110 @@ var createEthereumClient = (transport) => ({
|
|
|
648
652
|
})
|
|
649
653
|
});
|
|
650
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
|
+
|
|
651
759
|
// src/rpc/solana.ts
|
|
652
760
|
var SOLANA_RPC_METHODS = [
|
|
653
761
|
"getAccountInfo",
|
|
@@ -1410,6 +1518,10 @@ var createErpcClient = (config) => {
|
|
|
1410
1518
|
...sharedTransport,
|
|
1411
1519
|
endpoint: endpointWithPath(resolved.avalancheEndpoint, "/ava")
|
|
1412
1520
|
});
|
|
1521
|
+
const avalancheIndexTransport = (path) => new HttpJsonRpcTransport({
|
|
1522
|
+
...sharedTransport,
|
|
1523
|
+
endpoint: endpointWithPath(resolved.avalancheEndpoint, path)
|
|
1524
|
+
});
|
|
1413
1525
|
const solanaWebSocket = new WebSocketJsonRpcTransport({
|
|
1414
1526
|
endpoint: websocketUrl(resolved.endpoint, resolved.apiKey),
|
|
1415
1527
|
timeoutMs: resolved.timeoutMs,
|
|
@@ -1450,7 +1562,12 @@ var createErpcClient = (config) => {
|
|
|
1450
1562
|
subscriptions: new EthereumSubscriptions(ethereumWebSocket)
|
|
1451
1563
|
};
|
|
1452
1564
|
const avalanche = {
|
|
1453
|
-
...
|
|
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
|
+
}),
|
|
1454
1571
|
subscriptions: new EthereumSubscriptions(avalancheWebSocket)
|
|
1455
1572
|
};
|
|
1456
1573
|
return {
|
|
@@ -1684,6 +1801,12 @@ var createErpcCloudClient = (config) => {
|
|
|
1684
1801
|
};
|
|
1685
1802
|
};
|
|
1686
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;
|
|
1687
1810
|
exports.AccountClient = AccountClient;
|
|
1688
1811
|
exports.CloudCatalogClient = CloudCatalogClient;
|
|
1689
1812
|
exports.CloudCreditClient = CloudCreditClient;
|