The network name can be accessed via dataSource as follows:
import { dataSource } from "@graphprotocol/graph-ts";
const chainName = dataSource.network(); // returns network name
const chainId = ChainIds[chainName];
The list of network's supported on the graphs hosted service can be found here.
You can also configure the data source addresses listed in the subgraph.yaml
for multiple networks using a networks.json
config as shown in thegraph's docs.