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-registry
Usage
Loading the Registry
import { NetworksRegistry } from '@pinax/graph-networks-registry';
// Load from the latest compatible registry JSON at networks-registry.thegraph.com
const registry = await NetworksRegistry.fromLatestVersion();
// Load from specific version tag at networks-registry.thegraph.com
const registry = await NetworksRegistry.fromExactVersion('0.6.0');
const registry = await NetworksRegistry.fromExactVersion('0.6.x');
// Load from URL
const registry = await NetworksRegistry.fromUrl('https://networks-registry.thegraph.com/TheGraphNetworksRegistry.json');
// Load from local file
const registry = NetworksRegistry.fromFile('./TheGraphNetworksRegistry.json');
// Load from JSON string
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 mainnet = registry.getNetworkByAlias('eth');
if (mainnet) {
console.log(mainnet.fullName); // "Ethereum Mainnet"
}