diff --git a/components/SuperchainContractTable.tsx b/components/SuperchainContractTable.tsx new file mode 100644 index 000000000..5f6a41f74 --- /dev/null +++ b/components/SuperchainContractTable.tsx @@ -0,0 +1,65 @@ +import type { ReactElement } from 'react' +import { useEffect, useState } from 'react' +import { AddressTable, TableAddresses } from '@/components/AddressTable' + +const CONFIG_URL = 'https://raw.githubusercontent.com/ethereum-optimism/superchain-registry/main/superchain/configs/configs.json'; + +export function SuperchainContractTable({ + chain, + explorer, +}: { + chain: string, + explorer: string, +}): ReactElement { + const [config, setConfig] = useState | null>(null) + const [loading, setLoading] = useState(true) + const [error, setError] = useState(null) + + useEffect(() => { + async function fetchAddresses() { + try { + const response = await fetch(CONFIG_URL) + if (!response.ok) { + throw new Error('Failed to fetch config') + } + const data = await response.json() + setConfig(data) + } catch (err) { + setError(err.message) + console.error('Error fetching config:', err) + } finally { + setLoading(false) + } + } + + fetchAddresses() + }, []) + + if (loading) { + return
Loading...
+ } + + if (error) { + return
Error: {error}
+ } + + // Find the superchain config for the given chain. + const superchain = config?.superchains.find( + (sc: any) => sc.config.L1.ChainID.toString() === chain + ) + + // Create a TableAddresses object with the ProtocolVersions and SuperchainConfig addresses. + const addresses: TableAddresses | undefined = superchain && { + ProtocolVersions: superchain.config.ProtocolVersionsAddr, + SuperchainConfig: superchain.config.SuperchainConfigAddr, + }; + + return ( + + ) +} diff --git a/pages/chain/addresses.mdx b/pages/chain/addresses.mdx index 5b30eb9b4..4317dbf7d 100644 --- a/pages/chain/addresses.mdx +++ b/pages/chain/addresses.mdx @@ -7,6 +7,7 @@ description: This reference guide lists all the contract addresses for Mainnet a import { Callout } from 'nextra/components' import { L1ContractTable } from '@/components/L1ContractTable' import { L2ContractTable } from '@/components/L2ContractTable' +import { SuperchainContractTable } from '@/components/SuperchainContractTable' # Contract Addresses @@ -19,6 +20,10 @@ This page is automatically generated from packages in the [superchain-registry]( ## Mainnet +### Ethereum Superchain Contracts (L1) + + + ### Ethereum (L1) @@ -37,6 +42,10 @@ This page is automatically generated from packages in the [superchain-registry]( ## Testnet (Sepolia) +### Sepolia Superchain Contracts (L1) + + + ### Sepolia (L1)