-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexplorer.ts
More file actions
22 lines (20 loc) · 797 Bytes
/
explorer.ts
File metadata and controls
22 lines (20 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export function getTransactionExplorerUrl(
chainId: number | undefined,
transactionId: string
): string | null {
const networkMap: { [key: number]: string } = {
1: "https://etherscan.io/tx/", // Ethereum Mainnet
3: "https://ropsten.etherscan.io/tx/", // Ropsten Testnet
4: "https://rinkeby.etherscan.io/tx/", // Rinkeby Testnet
5: "https://goerli.etherscan.io/tx/", // Goerli Testnet
42: "https://kovan.etherscan.io/tx/", // Kovan Testnet
11155111: "https://sepolia.etherscan.io/tx/", // Sepolia Testnet
42220: "https://explorer.celo.org/tx/", // Celo Mainnet
};
if (chainId && networkMap[chainId]) {
return `${networkMap[chainId]}${transactionId}`;
} else {
console.error("Unsupported chain ID or chain ID is undefined.");
return null;
}
}