chainlist-rpcs 0.0.1

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/.babelrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-react"
4
+ ]
5
+ }
package/.eslintrc.cjs ADDED
@@ -0,0 +1,8 @@
1
+ // const { eslint_config } = require( './index.cjs' )
2
+ const { eslint_config } = require( 'airier' )
3
+
4
+ // Export the default eslint config
5
+ module.exports = {
6
+ ...eslint_config,
7
+ settings: { "react": { "version": "16" } },
8
+ }
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ echo "\n🤖 [ precommit hook ] linting before committing..."
5
+
6
+
7
+ # If errors, make it clear they cannot commit
8
+ if ! lint_outcome=$( npm run lint ); then
9
+ echo "🚨 [ precommit hook ] lint encountered blocking issues, fix them before committing\n"
10
+ echo "$lint_outcome"
11
+ exit 1
12
+ fi
13
+
14
+ # If warnings, suggest they fix them
15
+ if echo $lint_outcome | grep -q "warning"; then
16
+ echo "⚠️ [ precommit hook ] lint encountered warnings, consider fixing them before pushing\n"
17
+ echo "$lint_outcome"
18
+ exit 0
19
+ fi
20
+
21
+ echo "✅ [ precommit hook ] lint encountered no blocking issues\n"
package/.npmrc.bak ADDED
@@ -0,0 +1 @@
1
+ //registry.npmjs.org/:_authToken=${NPM_ACCESS_TOKEN}
@@ -0,0 +1,27 @@
1
+ {
2
+ "i18n-ally.localesPaths": [
3
+ "public/locales"
4
+ ],
5
+ "i18n-ally.keystyle": "nested",
6
+ "eslint.validate": [
7
+ "javascript",
8
+ "javascriptreact",
9
+ "typescript",
10
+ "typescriptreact"
11
+ ],
12
+ "editor.codeActionsOnSave": {
13
+ "source.fixAll.eslint": "explicit"
14
+ },
15
+ "editor.renderWhitespace": "all",
16
+ "editor.formatOnSave": true,
17
+ "eslint.format.enable": true,
18
+ "eslint.run": "onType",
19
+ "explorer.fileNesting.enabled": true,
20
+ "explorer.fileNesting.patterns": {
21
+ "vite.config.js": "*.js,.babelrc,.nvmrc,index.html,.gitignore",
22
+ ".env": ".env*,.*.json",
23
+ "firebase.json": "fire*,.fire*",
24
+ "package.json": "package-lock.json, yarn.lock, pnpm-lock.yaml,.eslint*,config.*,.npm*,.nvm*,.ncu*",
25
+ "README.md": "*.md,LICENSE",
26
+ }
27
+ }
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Unofficial chainlist RPC npm module
2
+
3
+ Installation: `npm install -S `
4
+
5
+ NOTE: This module is unofficial and not maintained by Chainlist. If you want to add RPC urls, please refer to the [DefiLlama/chainlist](https://github.com/DefiLlama/chainlist) repository.
6
+
7
+ NOTE 2: Keep in mind these RPCs are public and may have rate limits and imperfedt uptimel Use them at your own risk.
8
+
9
+ ## Usage of constants
10
+
11
+ The module exports constants that are objects you can access. The `rpcs` and `chains_by_id` constants which equal the chainlist sources [in this folder of their repository](https://github.com/DefiLlama/chainlist/tree/main/constants). The `chains_by_name` constant is an object that maps chain names to their id.
12
+
13
+ ```js
14
+ import { rpcs, chains_by_id, chains_by_name } from 'chainlist-rpc'
15
+
16
+ console.log( chains[1] ) // Output: "ethereum"
17
+ console.log( rpcs[1] ) // { rpcs: [ { url: String, tracking: String, trackingDetauls: String } ] }
18
+ console.log( chains_by_name["ethereum"] ) // Output: 1
19
+ ```
20
+
21
+ ## Usage of helper functions
22
+
23
+ This module makes available helpers that allow you to grab RPCs based on chain id or chain name.
24
+
25
+ ```js
26
+ /**
27
+ * Retrieves the RPC urls for a specified blockchain.
28
+ *
29
+ * @param {Object} params - The parameters for retrieving RPCs.
30
+ * @param {number} [params.chain_id] - The ID of the blockchain.
31
+ * @param {string} [params.chain_name] - The name of the blockchain.
32
+ * @param {Array} [params.allowed_tracking=[]] - An array of tracking objects. Options: none, limited, yes.
33
+ * @returns {Array} The list of RPCs for the specified blockchain.
34
+ * @throws {Error} If both chain_id and chain_name are specified but do not match.
35
+ */
36
+ export function get_rpcs_for_chain( { chain_id, chain_name, allowed_tracking=[] } )
37
+
38
+ /**
39
+ * Retrieves the RPC urls for the specified chains.
40
+ *
41
+ * @param {Object} params - The parameters object.
42
+ * @param {Array<string>} [params.chain_ids=[]] - An array of chain IDs.
43
+ * @param {Array<string>} [params.chain_names=[]] - An array of chain names.
44
+ * @param {Array} [params.allowed_tracking=[]] - An array of tracking objects. Options: none, limited, yes.
45
+ * @returns {Array} An array of RPCs for the specified chains.
46
+ */
47
+ export function get_rcpcs_for_chains( { chain_ids=[], chain_names=[], allowed_tracking=[] } )
48
+
49
+ ```
50
+
51
+ Example usage:
52
+
53
+ ```js
54
+ import { get_rcpcs_for_chain, get_rcpcs_for_chains } from 'chainlist-rpc'
55
+
56
+ const single_chain_by_id = get_rcpcs_for_chain( { chain_id: 1 } ) // Output: [ { url: String, tracking: String, trackingDetauls: String } ]
57
+ const single_chain_by_name = get_rcpcs_for_chain( { chain_name: "ethereum" } ) // Output: [ { url: String, tracking: String, trackingDetauls: String } ]
58
+
59
+ const multiple_chains_by_id = get_rcpcs_for_chains( { chain_ids: [1, 42161] } ) // Output: { 1: [ { url: String, tracking: String, trackingDetauls: String } ], 42161: [ { url: String, tracking: String, trackingDetauls: String } ], ethereum: [ { url: String, tracking: String, trackingDetauls: String } ], arbitrum: [ { url: String, tracking: String, trackingDetauls: String } ] }
60
+
61
+ const multiple_chains_by_name = get_rcpcs_for_chains( { chain_names: ["ethereum", "arbitrum"] } ) // Output: { 1: [ { url: String, tracking: String, trackingDetauls: String } ], 42161: [ { url: String, tracking: String, trackingDetauls: String } ], ethereum: [ { url: String, tracking: String, trackingDetauls: String } ], arbitrum: [ { url: String, tracking: String, trackingDetauls: String } ] }
62
+
63
+ ```
64
+
65
+ ## Example usage with viem
66
+
67
+ ```js
68
+ import { get_rcpcs_for_chain, get_rcpcs_for_chains } from 'chainlist-rpc'
69
+ import { arbitrum } from 'viem/chains'
70
+ import { createPublicClient, fallback, http, formatEther } from 'viem'
71
+
72
+ const your_private_rpc_endpoints = [ "https://your-private-rpc-endpoint.com", "https://your-private-rpc-endpoint-2.com" ]
73
+ const chainlink_rpc_endpoints = get_rcpcs_for_chain( { chain_name: 'arbitrum' } )
74
+ const rpc_endpoints = [ ...your_private_rpc_endpoints, ...chainlink_rpc_endpoints ]
75
+
76
+ const public_client = createPublicClient( {
77
+ chain: arbitrum,
78
+ transport: fallback( rpc_endpoints.map( ( rpc ) => http( rpc ) ) )
79
+ } )
80
+
81
+ const gas_price_wei = await public_client.getGasPrice()
82
+ ```
package/app.js ADDED
@@ -0,0 +1,7 @@
1
+ // Export the constants verbatim
2
+ export { default as rpcs } from './constants/extraRpcs'
3
+ export { default as chains_by_id } from './constants/chainIds'
4
+
5
+ // Export the helper functions
6
+ export { chains_by_name } from './modules/chains'
7
+ export { get_rpcs_for_chain, get_rcpcs_for_chains } from './modules/filter'