0xtrails
Version:
SDK for Trails
39 lines (33 loc) • 848 B
text/typescript
import { getChainInfo } from "./chains.js"
export type ExplorerUrlParams = {
txHash: string
chainId: number
}
export type ExplorerUrlForAddressParams = {
address: string
chainId: number
}
export function getBaseExplorerUrl(chainId: number): string {
const chain = getChainInfo(chainId)
if (chain) {
return `${chain.blockExplorers?.default?.url}`
}
return ""
}
export function getExplorerUrl({ txHash, chainId }: ExplorerUrlParams): string {
if (!txHash) {
return ""
}
const baseExplorerUrl = getBaseExplorerUrl(chainId)
return `${baseExplorerUrl}/tx/${txHash}`
}
export function getExplorerUrlForAddress({
address,
chainId,
}: ExplorerUrlForAddressParams): string {
if (!address) {
return ""
}
const baseExplorerUrl = getBaseExplorerUrl(chainId)
return `${baseExplorerUrl}/address/${address}`
}