diff --git a/src/address/Contract.tsx b/src/address/Contract.tsx index ae019a4..357e606 100644 --- a/src/address/Contract.tsx +++ b/src/address/Contract.tsx @@ -1,8 +1,10 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useContext } from "react"; import { ethers } from "ethers"; import ContentFrame from "../ContentFrame"; import Highlight from "react-highlight"; import InfoRow from "../components/InfoRow"; +import { sourcifyMetadata } from "../url"; +import { RuntimeContext } from "../useRuntime"; import "highlight.js/styles/stackoverflow-light.css"; import hljs from "highlight.js"; @@ -15,6 +17,7 @@ type ContractProps = { }; const Contract: React.FC = ({ checksummedAddress }) => { + const { provider } = useContext(RuntimeContext); const [rawMetadata, setRawMetadata] = useState(); useEffect(() => { if (!checksummedAddress) { @@ -24,7 +27,7 @@ const Contract: React.FC = ({ checksummedAddress }) => { const fetchMetadata = async () => { try { const result = await fetch( - `https://repo.sourcify.dev/contracts/full_match/1/${checksummedAddress}/metadata.json` + sourcifyMetadata(checksummedAddress, provider!.network.chainId) ); if (result.ok) { const json = await result.json(); @@ -40,7 +43,7 @@ const Contract: React.FC = ({ checksummedAddress }) => { } }; fetchMetadata(); - }, [checksummedAddress]); + }, [provider, checksummedAddress]); const [selected, setSelected] = useState(); diff --git a/src/url.ts b/src/url.ts index 00e3dc8..0d3c9e6 100644 --- a/src/url.ts +++ b/src/url.ts @@ -13,3 +13,9 @@ export const tokenLogoURL = ( export const blockURL = (blockNum: BlockTag) => `/block/${blockNum}`; export const blockTxsURL = (blockNum: BlockTag) => `/block/${blockNum}/txs`; + +export const sourcifyMetadata = ( + checksummedAddress: string, + networkId: number +) => + `http://localhost:7000/sourcify/contracts/full_match/${networkId}/${checksummedAddress}/metadata.json`;