chainlist-rpcs 0.2.10 → 0.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Unofficial chainlist RPC npm module
2
2
 
3
- Installation: `npm install -S chainlist-rpcs`
3
+ Installation: `npm install -S chainlist-rpcs`. See [npm package](https://www.npmjs.com/package/chainlist-rpcs).
4
4
 
5
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
6
 
@@ -14,7 +14,7 @@ The module exports constants that are objects you can access. The `rpcs` and `ch
14
14
  import { rpcs, chains_by_id, chains_by_name } from 'chainlist-rpcs'
15
15
 
16
16
  console.log( chains[1] ) // Output: "ethereum". Note that this is by chain id and not by index. 1 here refers to chain id 1.
17
- console.log( rpcs[1] ) // { rpcs: [ { url: String, tracking: String, trackingDetails: String } ] }.
17
+ console.log( rpcs[1] ) // [ { url: String, tracking: String, trackingDetails: String } ].
18
18
  console.log( chains_by_name["ethereum"] ) // Output: 1
19
19
  ```
20
20
 
package/app.js CHANGED
@@ -1,5 +1,5 @@
1
- // Export the constants verbatim
2
- export { default as rpcs } from './constants/extraRpcs'
1
+ // Export the constants
2
+ export { default as rpcs } from './modules/rpcs'
3
3
  export { default as chains_by_id } from './constants/chainIds'
4
4
 
5
5
  // Export the helper functions
@@ -0,0 +1,19 @@
1
+ import rpcs from '../constants/extraRpcs'
2
+
3
+ // The llama format is { [Number]: { rpcs: [] } }, we can simplify that
4
+ const simple_rpc_list = Object.keys( rpcs ).reduce( ( acc, chainId ) => {
5
+ acc[chainId] = rpcs[chainId].rpcs || []
6
+ return acc
7
+ },{} )
8
+
9
+ // The llama format for an RPC is sometimes and object and sometimes a string, let's normalize that
10
+ Object.keys( simple_rpc_list ).forEach( chainId => {
11
+ simple_rpc_list[chainId] = simple_rpc_list[chainId].map( rpc => {
12
+ if( typeof rpc === 'string' ) {
13
+ return { url: rpc }
14
+ }
15
+ return rpc
16
+ } )
17
+ } )
18
+
19
+ export default simple_rpc_list
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chainlist-rpcs",
3
- "version": "0.2.10",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Wrapper around the rpcs as published by DefiLlama/chainlist.",
6
6
  "main": "app.js",
@@ -29,4 +29,4 @@
29
29
  "husky": "^9.1.6",
30
30
  "vitest": "^2.1.5"
31
31
  }
32
- }
32
+ }
@@ -1,6 +1,7 @@
1
1
  import { describe, it, expect } from 'vitest'
2
2
 
3
- import { get_rpcs_for_chains, get_rpcs_for_chain } from '../modules/filter'
3
+ import { get_rpcs_for_chains, get_rpcs_for_chain, chains_by_name } from '../app'
4
+ import { chains_by_id } from '../app'
4
5
 
5
6
  describe( 'get_rpcs_for_chain', () => {
6
7
 
@@ -101,4 +102,22 @@ describe( 'get_rpcs_for_chains', () => {
101
102
 
102
103
  } )
103
104
 
105
+ } )
106
+
107
+ describe( 'Chain constant should have coherent values', () => {
108
+
109
+ it( 'Should have some expected chain ids', () => {
110
+ const expected_chain_ids = [ 1, 42161 ]
111
+ for( const chain_id of expected_chain_ids ) {
112
+ expect( chains_by_id[chain_id] ).toBeDefined()
113
+ }
114
+ } )
115
+
116
+ it( 'Should have some expected chain names', () => {
117
+ const expected_chain_names = [ 'ethereum', 'arbitrum' ]
118
+ for( const chain_name of expected_chain_names ) {
119
+ expect( chains_by_name[chain_name] ).toBeDefined()
120
+ }
121
+ } )
122
+
104
123
  } )