Package Exports
- @pinax/graph-networks-registry
- @pinax/graph-networks-registry/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@pinax/graph-networks-registry) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
The Graph Networks Registry Typescript Library
TypeScript types and helpers for The Graph Networks Registry.
Documentation available here.
Installation
npm install @pinax/graph-networks-registryFeatures
- Type-safe interfaces for The Graph Networks Registry
- Helper methods to load registry data from various sources
- Network lookup by ID and alias
Usage
Loading the Registry
import { NetworksRegistry } from '@pinax/graph-networks-registry';
// Load from latest version. Always compatible. Make sure you update the package to get the latest data.
const registry = await NetworksRegistry.fromLatestVersion();
// Load from specific version. Might throw if schema is not compatible.
const registry = await NetworksRegistry.fromExactVersion('0.6.0');
// Load from URL. Might throw if schema is not compatible.
const registry = await NetworksRegistry.fromUrl('https://registry.thegraph.com/TheGraphNetworksRegistry.json');
// Load from local file. Might throw if file is not found or schema is not compatible.
const registry = NetworksRegistry.fromFile('./TheGraphNetworksRegistry.json');
// Load from JSON string. Might throw if schema is not compatible.
const registry = NetworksRegistry.fromJson(jsonString);Working with Networks
// Find network by ID
const mainnet = registry.getNetworkById('mainnet');
if (mainnet) {
console.log(mainnet.fullName); // "Ethereum Mainnet"
console.log(mainnet.caip2Id); // "eip155:1"
}
// Find network by alias
const ethereum = registry.getNetworkByAlias('eth');
if (ethereum) {
console.log(ethereum.fullName); // "Ethereum Mainnet"
}