@chain-registry/client 1.21.17 → 1.23.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.
Files changed (2) hide show
  1. package/README.md +173 -13
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -12,10 +12,162 @@
12
12
  <a href="https://www.npmjs.com/package/@chain-registry/client"><img height="20" src="https://img.shields.io/github/package-json/v/cosmology-tech/chain-registry?filename=packages%2Fclient%2Fpackage.json"></a>
13
13
  </p>
14
14
 
15
- A Client for `chain-registry` that allows you to dynamically fetch data.
15
+ The `@chain-registry/client` package provides a client for dynamically fetching and managing chain and asset data from the Cosmos chain registry. This tool is essential for developers who need to access up-to-date blockchain information, including asset lists and IBC data.
16
+
17
+ - [Introduction](#chain-registryclient)
18
+ - [Installation](#installation)
19
+ - [Usage](#usage)
20
+ - [ChainRegistryClient](#chainregistryclient)
21
+ - [Initializing the Client](#initializing-the-client)
22
+ - [Methods](#methods)
23
+ - [Fetching Chain and Asset Data](#fetching-chain-and-asset-data)
24
+ - [Accessing Chain Information](#accessing-chain-information)
25
+ - [Retrieving Asset Lists](#retrieving-asset-lists)
26
+ - [ChainRegistryFetcher](#chainregistryfetcher)
27
+ - [Fetching Data](#fetching-data)
28
+ - [Fetching Schemata](#fetching-schemata)
29
+ - [fetchUrls](#fetchurls)
30
+ - [fetch](#fetch)
31
+ - [Asset Lists](#asset-lists)
32
+ - [Chain Info](#chain-info)
33
+ - [Related Projects](#related)
34
+ - [Credits](#credits)
35
+ - [Disclaimer](#disclaimer)
36
+
37
+ ## Installation
38
+
39
+ ```
40
+ npm install @chain-registry/client
41
+ ```
16
42
 
17
43
  ## Usage
18
44
 
45
+ We recommend using the [`ChainRegistryClient`](#chainregistryclient) directly, the [ChainRegistryFetcher](#chainregistryfetcher) is lower-level if you don't need a higher-level class.
46
+
47
+ ### ChainRegistryClient
48
+
49
+ `ChainRegistryClient` dynamically fetches and manages chain and asset data from the `chain-registry`.
50
+
51
+ #### Initializing the Client
52
+
53
+ ```js
54
+ import { ChainRegistryClient } from '@chain-registry/client';
55
+
56
+ const client = new ChainRegistryClient({
57
+ chainNames: ['osmosis', 'juno']
58
+ });
59
+ ```
60
+
61
+ After instantiation, you can use client to access chain and asset information, along with IBC data.
62
+
63
+ #### ChainRegistryClient Options
64
+
65
+ While the default usage above is simple, you can customize it.
66
+
67
+ The `ChainRegistryClient` constructor accepts an `options` object you can specify:
68
+
69
+ - `chainNames` (required): An array of strings representing the names of the chains you want to fetch data for. This option is essential to determine which chains' data will be managed by the client.
70
+
71
+ - `assetListNames` (optional): An array of strings specifying the names of the chains for which asset lists should be fetched. If not provided, the client uses the `chainNames` array as the default list.
72
+
73
+ - `ibcNamePairs` (optional): An array of string arrays, where each nested array contains two elements representing a pair of chain names. This setting specifies the Inter-Blockchain Communication (IBC) connections between the chains for which data should be considered. It is particularly useful for limiting the scope of IBC-related data processing.
74
+
75
+ - `baseUrl` (optional): A string representing the base URL for fetching the chain registry data. If not specified, the client defaults to the official Cosmos chain registry on GitHub (`https://raw.githubusercontent.com/cosmos/chain-registry/master`).
76
+
77
+ #### Initialization Examples
78
+
79
+ Here is a client with specified chain names and limited IBC name pairs, and custom `baseUrl`:
80
+ ```js
81
+ const client = new ChainRegistryClient({
82
+ chainNames: ['osmosis', 'juno', 'stargaze', 'cosmoshub'],
83
+ ibcNamePairs: [['osmosis', 'stargaze']],
84
+ baseUrl: 'https://yourregistry.com/'
85
+ });
86
+ ```
87
+
88
+ Here is a client with specified chain names and limited asset list, and limited IBC name pairs:
89
+
90
+ ```js
91
+ const clientWithAssetLists = new ChainRegistryClient({
92
+ chainNames: ['osmosis', 'juno', 'stargaze'],
93
+ assetListNames: ['osmosis', 'juno'],
94
+ ibcNamePairs: [['osmosis', 'juno']]
95
+ });
96
+ ```
97
+
98
+ Let's walk through this example where you can specify which IBC connections you're interested in:
99
+
100
+ ```ts
101
+ import { ChainRegistryClient } from '@chain-registry/client';
102
+
103
+ const client = new ChainRegistryClient({
104
+ chainNames: ['osmosis', 'juno', 'stargaze', 'cosmoshub'],
105
+ ibcNamePairs: [['osmosis', 'stargaze']]
106
+ });
107
+ ```
108
+
109
+ In this example, the `chainNames` option includes four chains, but `ibcNamePairs` only includes a pair between osmosis and stargaze. This configuration means that the client will fetch and manage data for all four specified chains, but when it comes to generating asset lists with `getGeneratedAssetLists()`, it will only consider the IBC connections between osmosis and stargaze for IBC-connected assets.
110
+
111
+ #### Methods
112
+
113
+ - `fetchUrls()`: Asynchronously fetches the data for all the configured URLs and stores the results internally within the client instance.
114
+ - `getChain(chainName)`: Returns the `Chain` object for the specified chain name.
115
+ - `getChainInfo(chainName)`: Retrieves detailed information about the specified chain, including its configuration, assets, and IBC connections.
116
+ - `getAssetList(chainName)`: Obtains a list of assets available on the specified chain.
117
+ - `getChainAssetList(chainName)`: Returns the `AssetList` for the specified chain.
118
+ - `getGeneratedAssetLists(chainName)`: Generates and returns `AssetList[]` for the specified chain, including IBC-connected assets.
119
+ - `getChainIbcData(chainName)`: Retrieves IBC data related to the specified chain.
120
+
121
+ #### Fetching chain and asset data
122
+
123
+ To initiate the data fetching process, the ChainRegistryClient must first execute the fetchUrls method. This method asynchronously retrieves data from the predefined URLs based on the configuration provided during the client's instantiation.
124
+
125
+ ```js
126
+ await client.fetchUrls();
127
+ ```
128
+
129
+ In this line, `client.fetchUrls()` asynchronously fetches the chain and asset data for the chains specified in the client's configuration. This process involves making HTTP requests to the URLs constructed from the base URL and the chain names, asset list names, and IBC name pairs provided in the `ChainRegistryClientOptions`.
130
+
131
+ #### Accessing Chain Information
132
+
133
+ After fetching the data, you can access detailed information about a specific chain using the `getChainInfo` method. This method returns a comprehensive object containing data about the requested chain, including its assets, IBC connections, and other metadata.
134
+
135
+ ```js
136
+ const osmosisInfo = client.getChainInfo('osmosis');
137
+ // returns ChainInfo, which is an object containing everything
138
+ ```
139
+
140
+ if you just want the `Chain` object, you can do:
141
+
142
+ ```js
143
+ const osmosisInfo = client.getChain('osmosis');
144
+ // returns Chain from `@chain-registry/types`
145
+ ```
146
+
147
+
148
+ #### Retrieving Asset Lists
149
+
150
+ Here, `client.getAssetList('juno')` fetches the asset list for the Juno chain. The `junoAssets` variable will hold an array of assets defined on the Juno chain, detailing each asset's properties such as its name, symbol, and other asset-specific information.
151
+
152
+ ```js
153
+ const junoAssets = client.getAssetList('juno');
154
+ // returns AssetList from '@chain-registry/types'
155
+ ```
156
+
157
+ If you want to get the IBC denominations, and the asset lists based on the IBC connections, you can use `getGeneratedAssetLists()`:
158
+
159
+ ```js
160
+ const generatedOsmosisAssets = client.getGeneratedAssetLists('osmosis');
161
+ // returns AssetList from '@chain-registry/types' — including generated IBC assets based on IBC connections
162
+ ```
163
+
164
+
165
+ ### ChainRegistryFetcher
166
+
167
+ `ChainRegistryFetcher` is a lower-level component used by `ChainRegistryClient` for fetching data from specified URLs.
168
+
169
+ #### Fetching data
170
+
19
171
  ```js
20
172
  import { ChainRegistryFetcher, ChainRegistryFetcherOptions } from '@chain-registry/client';
21
173
 
@@ -33,13 +185,13 @@ const registry = new ChainRegistryFetcher(options);
33
185
  await registry.fetchUrls();
34
186
  ```
35
187
 
36
- ## Fetching Schemata
188
+ #### Fetching Schemata
37
189
 
38
190
  We currently only support fetching JSON schemas as defined in https://github.com/cosmos/chain-registry. Supported are `assetlist.schema.json`, `chain.schema.json` and `ibc_data.schema.json`.
39
191
 
40
- ### fetchUrls
192
+ #### fetchUrls
41
193
 
42
- You can set the `ChainRegistry.urls` property and call `ChainRegistry.fetchUrls()`
194
+ You can set the `ChainRegistryFetcher.urls` property and call `ChainRegistryFetcher.fetchUrls()`
43
195
 
44
196
  ```js
45
197
  registry.urls = [
@@ -48,15 +200,15 @@ registry.urls = [
48
200
  await registry.fetchUrls();
49
201
  ```
50
202
 
51
- ### fetch
203
+ #### fetch
52
204
 
53
- Or, you can simply call `ChainRegistry.fetch()`
205
+ Or, you can simply call `ChainRegistryFetcher.fetch()`
54
206
 
55
207
  ```js
56
208
  await registry.fetch('https://some-json-schema.com/some-schema.json');
57
209
  ```
58
210
 
59
- ## Asset lists
211
+ #### Asset lists
60
212
 
61
213
  You can get generated asset lists directly from the registry:
62
214
 
@@ -100,13 +252,21 @@ const nativeAssetList: AssetList = chainInfo.nativeAssetList;
100
252
 
101
253
  Checkout these related projects:
102
254
 
103
- * [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) for generated CosmWasm contract Typescript classes
104
- * [@cosmology/telescope](https://github.com/cosmology-tech/telescope) a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.
105
- * [chain-registry](https://github.com/cosmology-tech/chain-registry) an npm module for the official Cosmos chain-registry.
106
- * [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) A wallet connector for the Cosmos ⚛️
107
- * [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) set up a modern Cosmos app by running one command.
108
- * [starship](https://github.com/cosmology-tech/starship) a k8s-based unified development environment for Cosmos Ecosystem
255
+ * [@cosmology/telescope](https://github.com/cosmology-tech/telescope) Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules.
256
+ * [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) Convert your CosmWasm smart contracts into dev-friendly TypeScript classes.
257
+ * [chain-registry](https://github.com/cosmology-tech/chain-registry) Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application.
258
+ * [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface.
259
+ * [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) Set up a modern Cosmos app by running one command.
260
+ * [interchain-ui](https://github.com/cosmology-tech/interchain-ui) The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit.
261
+ * [starship](https://github.com/cosmology-tech/starship) Unified Testing and Development for the Interchain.
109
262
 
110
263
  ## Credits
111
264
 
112
265
  🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.zone/validator)
266
+
267
+
268
+ ## Disclaimer
269
+
270
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
271
+
272
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/client",
3
- "version": "1.21.17",
3
+ "version": "1.23.0",
4
4
  "description": "Chain Registry Client",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmology-tech/chain-registry",
@@ -75,10 +75,10 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@babel/runtime": "^7.21.0",
78
- "@chain-registry/types": "^0.18.19",
79
- "@chain-registry/utils": "^1.19.18",
78
+ "@chain-registry/types": "^0.20.0",
79
+ "@chain-registry/utils": "^1.21.0",
80
80
  "bfs-path": "^1.0.2",
81
81
  "cross-fetch": "^3.1.5"
82
82
  },
83
- "gitHead": "dfe1bbd1892c0a50361f93f592f8086219683e0c"
83
+ "gitHead": "0b79e2d7b81bef1bf608ddea5bf7698904d2df20"
84
84
  }