@pinax/graph-networks-registry
v0.6.3
Published
TypeScript types and helpers for The Graph Networks Registry
Downloads
237
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
Features
- 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"
}