Skip to content

Commit 5ec2578

Browse files
authored
Merge pull request #897 from ethereum-optimism/sc/superchain-addrs
feat: add superchain contract address table
2 parents 5bbb9a4 + ef4022c commit 5ec2578

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import type { ReactElement } from 'react'
2+
import { useEffect, useState } from 'react'
3+
import { AddressTable, TableAddresses } from '@/components/AddressTable'
4+
5+
const CONFIG_URL = 'https://raw.githubusercontent.com/ethereum-optimism/superchain-registry/main/superchain/configs/configs.json';
6+
7+
export function SuperchainContractTable({
8+
chain,
9+
explorer,
10+
}: {
11+
chain: string,
12+
explorer: string,
13+
}): ReactElement {
14+
const [config, setConfig] = useState<Record<string, any> | null>(null)
15+
const [loading, setLoading] = useState(true)
16+
const [error, setError] = useState<string | null>(null)
17+
18+
useEffect(() => {
19+
async function fetchAddresses() {
20+
try {
21+
const response = await fetch(CONFIG_URL)
22+
if (!response.ok) {
23+
throw new Error('Failed to fetch config')
24+
}
25+
const data = await response.json()
26+
setConfig(data)
27+
} catch (err) {
28+
setError(err.message)
29+
console.error('Error fetching config:', err)
30+
} finally {
31+
setLoading(false)
32+
}
33+
}
34+
35+
fetchAddresses()
36+
}, [])
37+
38+
if (loading) {
39+
return <div>Loading...</div>
40+
}
41+
42+
if (error) {
43+
return <div>Error: {error}</div>
44+
}
45+
46+
// Find the superchain config for the given chain.
47+
const superchain = config?.superchains.find(
48+
(sc: any) => sc.config.L1.ChainID.toString() === chain
49+
)
50+
51+
// Create a TableAddresses object with the ProtocolVersions and SuperchainConfig addresses.
52+
const addresses: TableAddresses | undefined = superchain && {
53+
ProtocolVersions: superchain.config.ProtocolVersionsAddr,
54+
SuperchainConfig: superchain.config.SuperchainConfigAddr,
55+
};
56+
57+
return (
58+
<AddressTable
59+
chain={chain}
60+
explorer={explorer}
61+
legacy={false}
62+
addresses={addresses}
63+
/>
64+
)
65+
}

pages/chain/addresses.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ description: This reference guide lists all the contract addresses for Mainnet a
77
import { Callout } from 'nextra/components'
88
import { L1ContractTable } from '@/components/L1ContractTable'
99
import { L2ContractTable } from '@/components/L2ContractTable'
10+
import { SuperchainContractTable } from '@/components/SuperchainContractTable'
1011

1112
# Contract Addresses
1213

@@ -19,6 +20,10 @@ This page is automatically generated from packages in the [superchain-registry](
1920

2021
## Mainnet
2122

23+
### Ethereum Superchain Contracts (L1)
24+
25+
<SuperchainContractTable chain="1" explorer="1" />
26+
2227
### Ethereum (L1)
2328

2429
<L1ContractTable chain="10" explorer="1" legacy={false} />
@@ -37,6 +42,10 @@ This page is automatically generated from packages in the [superchain-registry](
3742

3843
## Testnet (Sepolia)
3944

45+
### Sepolia Superchain Contracts (L1)
46+
47+
<SuperchainContractTable chain="11155111" explorer="11155111" />
48+
4049
### Sepolia (L1)
4150

4251
<L1ContractTable chain="11155420" explorer="11155111" legacy={false} />

0 commit comments

Comments
 (0)