@pinax/graph-networks-registry

The Graph Networks Registry Typescript Library

npm version Documentation License: MIT

TypeScript types and helpers for The Graph Networks Registry.

Documentation available here.

npm install @pinax/graph-networks-registry
import { NetworksRegistry } from '@pinax/graph-networks-registry';

// Load from the latest compatible registry JSON at registry.thegraph.com
const registry = await NetworksRegistry.fromLatestVersion();

// Load from specific version tag at 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://registry.thegraph.com/TheGraphNetworksRegistry.json');

// Load from local file
const registry = NetworksRegistry.fromFile('./TheGraphNetworksRegistry.json');

// Load from JSON string
const registry = NetworksRegistry.fromJson(jsonString);
// 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"
}