@solbuilder_io/rpc-health 1.0.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 +29 -0
- package/index.js +46 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @solbuilder_io/rpc-health
|
|
2
|
+
|
|
3
|
+
Lightweight RPC endpoint health checker for multiple blockchains.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
```bash
|
|
7
|
+
npm install @solbuilder_io/rpc-health
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
```javascript
|
|
12
|
+
const rpc = require("@solbuilder_io/rpc-health");
|
|
13
|
+
|
|
14
|
+
// Check all default RPCs
|
|
15
|
+
rpc.checkAll().then(console.log);
|
|
16
|
+
// { solana: { url: "...", status: 200, latency: 45, healthy: true }, ... }
|
|
17
|
+
|
|
18
|
+
// Check a single endpoint
|
|
19
|
+
rpc.checkRPC("https://api.mainnet-beta.solana.com").then(console.log);
|
|
20
|
+
|
|
21
|
+
// Find fastest RPC for a chain
|
|
22
|
+
rpc.findFastest("ethereum").then(console.log);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Supported Chains
|
|
26
|
+
Solana, Ethereum, BSC, Polygon, Avalanche
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const http = require("http");
|
|
5
|
+
|
|
6
|
+
const DEFAULT_RPCS = {
|
|
7
|
+
solana: "https://api.mainnet-beta.solana.com",
|
|
8
|
+
ethereum: "https://eth.llamarpc.com",
|
|
9
|
+
bsc: "https://bsc-dataseed.binance.org",
|
|
10
|
+
polygon: "https://polygon-rpc.com",
|
|
11
|
+
avalanche: "https://api.avax.network/ext/bc/C/rpc",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function checkRPC(url, timeout = 5000) {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
const start = Date.now();
|
|
17
|
+
const client = url.startsWith("https") ? https : http;
|
|
18
|
+
const req = client.get(url, { timeout }, (res) => {
|
|
19
|
+
resolve({
|
|
20
|
+
url,
|
|
21
|
+
status: res.statusCode,
|
|
22
|
+
latency: Date.now() - start,
|
|
23
|
+
healthy: res.statusCode === 200 || res.statusCode === 405,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
req.on("error", () => resolve({ url, status: 0, latency: -1, healthy: false }));
|
|
27
|
+
req.on("timeout", () => { req.destroy(); resolve({ url, status: 0, latency: timeout, healthy: false }); });
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function checkAll(customRpcs = {}) {
|
|
32
|
+
const rpcs = { ...DEFAULT_RPCS, ...customRpcs };
|
|
33
|
+
const results = {};
|
|
34
|
+
for (const [chain, url] of Object.entries(rpcs)) {
|
|
35
|
+
results[chain] = await checkRPC(url);
|
|
36
|
+
}
|
|
37
|
+
return results;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function findFastest(chain) {
|
|
41
|
+
if (!DEFAULT_RPCS[chain]) return null;
|
|
42
|
+
const result = await checkRPC(DEFAULT_RPCS[chain]);
|
|
43
|
+
return { chain, ...result };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = { checkRPC, checkAll, findFastest, DEFAULT_RPCS };
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solbuilder_io/rpc-health",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightweight RPC endpoint health checker \u2014 check latency and availability for Solana, Ethereum, and EVM chain RPCs",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js"
|
|
8
|
+
],
|
|
9
|
+
"keywords": [
|
|
10
|
+
"rpc",
|
|
11
|
+
"health",
|
|
12
|
+
"latency",
|
|
13
|
+
"solana",
|
|
14
|
+
"ethereum",
|
|
15
|
+
"endpoint",
|
|
16
|
+
"web3",
|
|
17
|
+
"blockchain"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/solbuilder-io/rpc-health"
|
|
26
|
+
}
|
|
27
|
+
}
|