@elsoul/erpc-sdk 0.4.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 +17 -3
- package/dist/index.cjs +32 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +32 -1
- 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-Chain, 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,18 @@ 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 |
|
|
49
53
|
| `erpc.price` | Price metadata, updates, and streams |
|
|
50
54
|
| `erpc.account` | ERPC token balance |
|
|
51
55
|
| `erpc.usage` | Masked monthly API-key usage |
|
|
52
56
|
|
|
57
|
+
`avalancheEndpoint` defaults to `https://ava-rpc.erpc.global` and can be
|
|
58
|
+
overridden independently from the shared `endpoint` option. The SDK uses its
|
|
59
|
+
`/ava` HTTP route and `/ava-ws` WebSocket route. The Avalanche namespace uses
|
|
60
|
+
the Ethereum-compatible typed catalog; use `raw` for additional C-Chain
|
|
61
|
+
methods.
|
|
62
|
+
|
|
53
63
|
## Examples
|
|
54
64
|
|
|
55
65
|
```ts
|
|
@@ -59,6 +69,10 @@ const block = await erpc.ethereum.rpc
|
|
|
59
69
|
.eth_getBlockByNumber('latest', false)
|
|
60
70
|
.send()
|
|
61
71
|
|
|
72
|
+
const avalancheBlock = await erpc.avalanche.rpc
|
|
73
|
+
.eth_getBlockByNumber('latest', false)
|
|
74
|
+
.send()
|
|
75
|
+
|
|
62
76
|
const prices = await erpc.price.getLatestPriceUpdates({
|
|
63
77
|
ids: [feedId],
|
|
64
78
|
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 ?? {},
|
|
@@ -1394,6 +1406,10 @@ var createErpcClient = (config) => {
|
|
|
1394
1406
|
...sharedTransport,
|
|
1395
1407
|
endpoint: ethereumEndpoint
|
|
1396
1408
|
});
|
|
1409
|
+
const avalancheTransport = new HttpJsonRpcTransport({
|
|
1410
|
+
...sharedTransport,
|
|
1411
|
+
endpoint: endpointWithPath(resolved.avalancheEndpoint, "/ava")
|
|
1412
|
+
});
|
|
1397
1413
|
const solanaWebSocket = new WebSocketJsonRpcTransport({
|
|
1398
1414
|
endpoint: websocketUrl(resolved.endpoint, resolved.apiKey),
|
|
1399
1415
|
timeoutMs: resolved.timeoutMs,
|
|
@@ -1404,6 +1420,15 @@ var createErpcClient = (config) => {
|
|
|
1404
1420
|
timeoutMs: resolved.timeoutMs,
|
|
1405
1421
|
...resolved.webSocket === void 0 ? {} : { webSocket: resolved.webSocket }
|
|
1406
1422
|
});
|
|
1423
|
+
const avalancheWebSocket = new WebSocketJsonRpcTransport({
|
|
1424
|
+
endpoint: websocketUrl(
|
|
1425
|
+
resolved.avalancheEndpoint,
|
|
1426
|
+
resolved.apiKey,
|
|
1427
|
+
"/ava-ws"
|
|
1428
|
+
),
|
|
1429
|
+
timeoutMs: resolved.timeoutMs,
|
|
1430
|
+
...resolved.webSocket === void 0 ? {} : { webSocket: resolved.webSocket }
|
|
1431
|
+
});
|
|
1407
1432
|
const priceTransport = new RestTransport({
|
|
1408
1433
|
...sharedTransport,
|
|
1409
1434
|
endpoint: resolved.endpoint
|
|
@@ -1424,15 +1449,21 @@ var createErpcClient = (config) => {
|
|
|
1424
1449
|
...createEthereumClient(ethereumTransport),
|
|
1425
1450
|
subscriptions: new EthereumSubscriptions(ethereumWebSocket)
|
|
1426
1451
|
};
|
|
1452
|
+
const avalanche = {
|
|
1453
|
+
...createEthereumClient(avalancheTransport),
|
|
1454
|
+
subscriptions: new EthereumSubscriptions(avalancheWebSocket)
|
|
1455
|
+
};
|
|
1427
1456
|
return {
|
|
1428
1457
|
solana,
|
|
1429
1458
|
ethereum,
|
|
1459
|
+
avalanche,
|
|
1430
1460
|
price: new PriceClient(priceTransport),
|
|
1431
1461
|
account: new AccountClient(accountTransport),
|
|
1432
1462
|
usage: new UsageClient(userTransport),
|
|
1433
1463
|
close: () => {
|
|
1434
1464
|
solana.subscriptions.close();
|
|
1435
1465
|
ethereum.subscriptions.close();
|
|
1466
|
+
avalanche.subscriptions.close();
|
|
1436
1467
|
}
|
|
1437
1468
|
};
|
|
1438
1469
|
};
|
|
@@ -1658,6 +1689,7 @@ exports.CloudCatalogClient = CloudCatalogClient;
|
|
|
1658
1689
|
exports.CloudCreditClient = CloudCreditClient;
|
|
1659
1690
|
exports.CloudResourcesClient = CloudResourcesClient;
|
|
1660
1691
|
exports.DEFAULT_ACCOUNT_ENDPOINT = DEFAULT_ACCOUNT_ENDPOINT;
|
|
1692
|
+
exports.DEFAULT_AVALANCHE_ENDPOINT = DEFAULT_AVALANCHE_ENDPOINT;
|
|
1661
1693
|
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
1662
1694
|
exports.DEFAULT_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;
|
|
1663
1695
|
exports.DEFAULT_USER_ENDPOINT = DEFAULT_USER_ENDPOINT;
|