diff --git a/data/networks.json b/data/networks.json index f2a7699..fc0b5f4 100644 --- a/data/networks.json +++ b/data/networks.json @@ -101,7 +101,7 @@ }, { "type": "explorer", - "url": "https://zetachain-athens-2.blockscout.com", + "url": "https://zetachain-athens-3.blockscout.com", "tx": "/tx/${tx}", "address": "/address/${address}" } diff --git a/src/getExplorers.ts b/src/getExplorers.ts new file mode 100644 index 0000000..5114de9 --- /dev/null +++ b/src/getExplorers.ts @@ -0,0 +1,30 @@ +import { NetworksSchema } from "./types"; +import networks from "./networks"; + +export const getExplorers = ( + input: string, + inputType: "address" | "tx", + networkKey: keyof NetworksSchema +): string[] => { + const network = networks[networkKey as keyof typeof networks]; + if (!network) { + throw new Error("Network not found"); + } + + if (!("apps" in network) || !Array.isArray(network.apps)) { + throw new Error("Explorers not available for the provided network"); + } + + const explorerApps = network.apps.filter((app) => app.type === "explorer"); + + const urls: string[] = []; + for (const app of explorerApps) { + if (inputType === "address" && app.address) { + urls.push(app.url + app.address.replace("${address}", input)); + } else if (inputType === "tx" && app.tx) { + urls.push(app.url + app.tx.replace("${tx}", input)); + } + } + + return urls; +}; diff --git a/src/index.ts b/src/index.ts index 89a4888..b87b854 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export * from "./getEndpoints"; export * from "./getHardhatConfigNetworks"; export * from "./getSupportedNetworks"; +export * from "./getExplorers"; export { default as networks } from "./networks"; diff --git a/src/types.ts b/src/types.ts index 532039a..aeb32c1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,6 +8,7 @@ export type ApiType = | "evm" | "tendermint-rpc" + | "tendermint-http" | "cosmos-http" | "tendermint-ws" | "cosmos-grpc"