-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #685 from scaffold-eth/backmerge-main
Weekly CLI backmerge
- Loading branch information
Showing
75 changed files
with
795 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"create-eth": patch | ||
--- | ||
|
||
- App router migration (#535) | ||
- Update hardhat package plugins and add hardhat-verify (#637) | ||
- Update homepage file route and add Viem to README tech stack (#691) | ||
- Ethers v6 migration in hardhat (#692) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn lint-staged --verbose | ||
yarn lint-staged --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
templates/base/packages/nextjs/app/blockexplorer/_components/AddressComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { BackButton } from "./BackButton"; | ||
import { ContractTabs } from "./ContractTabs"; | ||
import { Address, Balance } from "~~/components/scaffold-eth"; | ||
|
||
export const AddressComponent = ({ | ||
address, | ||
contractData, | ||
}: { | ||
address: string; | ||
contractData: { bytecode: string; assembly: string } | null; | ||
}) => { | ||
return ( | ||
<div className="m-10 mb-20"> | ||
<div className="flex justify-start mb-5"> | ||
<BackButton /> | ||
</div> | ||
<div className="col-span-5 grid grid-cols-1 lg:grid-cols-2 gap-8 lg:gap-10"> | ||
<div className="col-span-1 flex flex-col"> | ||
<div className="bg-base-100 border-base-300 border shadow-md shadow-secondary rounded-3xl px-6 lg:px-8 mb-6 space-y-1 py-4 overflow-x-auto"> | ||
<div className="flex"> | ||
<div className="flex flex-col gap-1"> | ||
<Address address={address} format="long" /> | ||
<div className="flex gap-1 items-center"> | ||
<span className="font-bold text-sm">Balance:</span> | ||
<Balance address={address} className="text" /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<ContractTabs address={address} contractData={contractData} /> | ||
</div> | ||
); | ||
}; |
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
...nents/blockexplorer/AddressStorageTab.tsx → ...xplorer/_components/AddressStorageTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
templates/base/packages/nextjs/app/blockexplorer/_components/BackButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
|
||
export const BackButton = () => { | ||
const router = useRouter(); | ||
return ( | ||
<button className="btn btn-sm btn-primary" onClick={() => router.back()}> | ||
Back | ||
</button> | ||
); | ||
}; |
92 changes: 92 additions & 0 deletions
92
templates/base/packages/nextjs/app/blockexplorer/_components/ContractTabs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
import { AddressCodeTab } from "./AddressCodeTab"; | ||
import { AddressLogsTab } from "./AddressLogsTab"; | ||
import { AddressStorageTab } from "./AddressStorageTab"; | ||
import { PaginationButton } from "./PaginationButton"; | ||
import { TransactionsTable } from "./TransactionsTable"; | ||
import { createPublicClient, http } from "viem"; | ||
import { hardhat } from "viem/chains"; | ||
import { useFetchBlocks } from "~~/hooks/scaffold-eth"; | ||
|
||
type AddressCodeTabProps = { | ||
bytecode: string; | ||
assembly: string; | ||
}; | ||
|
||
type PageProps = { | ||
address: string; | ||
contractData: AddressCodeTabProps | null; | ||
}; | ||
|
||
const publicClient = createPublicClient({ | ||
chain: hardhat, | ||
transport: http(), | ||
}); | ||
|
||
export const ContractTabs = ({ address, contractData }: PageProps) => { | ||
const { blocks, transactionReceipts, currentPage, totalBlocks, setCurrentPage } = useFetchBlocks(); | ||
const [activeTab, setActiveTab] = useState("transactions"); | ||
const [isContract, setIsContract] = useState(false); | ||
|
||
useEffect(() => { | ||
const checkIsContract = async () => { | ||
const contractCode = await publicClient.getBytecode({ address: address }); | ||
setIsContract(contractCode !== undefined && contractCode !== "0x"); | ||
}; | ||
|
||
checkIsContract(); | ||
}, [address]); | ||
|
||
const filteredBlocks = blocks.filter(block => | ||
block.transactions.some(tx => { | ||
if (typeof tx === "string") { | ||
return false; | ||
} | ||
return tx.from.toLowerCase() === address.toLowerCase() || tx.to?.toLowerCase() === address.toLowerCase(); | ||
}), | ||
); | ||
|
||
return ( | ||
<> | ||
{isContract && ( | ||
<div className="tabs tabs-lifted w-min"> | ||
<button | ||
className={`tab ${activeTab === "transactions" ? "tab-active" : ""}`} | ||
onClick={() => setActiveTab("transactions")} | ||
> | ||
Transactions | ||
</button> | ||
<button className={`tab ${activeTab === "code" ? "tab-active" : ""}`} onClick={() => setActiveTab("code")}> | ||
Code | ||
</button> | ||
<button | ||
className={`tab ${activeTab === "storage" ? "tab-active" : ""}`} | ||
onClick={() => setActiveTab("storage")} | ||
> | ||
Storage | ||
</button> | ||
<button className={`tab ${activeTab === "logs" ? "tab-active" : ""}`} onClick={() => setActiveTab("logs")}> | ||
Logs | ||
</button> | ||
</div> | ||
)} | ||
{activeTab === "transactions" && ( | ||
<div className="pt-4"> | ||
<TransactionsTable blocks={filteredBlocks} transactionReceipts={transactionReceipts} /> | ||
<PaginationButton | ||
currentPage={currentPage} | ||
totalItems={Number(totalBlocks)} | ||
setCurrentPage={setCurrentPage} | ||
/> | ||
</div> | ||
)} | ||
{activeTab === "code" && contractData && ( | ||
<AddressCodeTab bytecode={contractData.bytecode} assembly={contractData.assembly} /> | ||
)} | ||
{activeTab === "storage" && <AddressStorageTab address={address} />} | ||
{activeTab === "logs" && <AddressLogsTab address={address} />} | ||
</> | ||
); | ||
}; |
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
...js/components/blockexplorer/SearchBar.tsx → ...p/blockexplorer/_components/SearchBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ponents/blockexplorer/TransactionHash.tsx → ...kexplorer/_components/TransactionHash.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nents/blockexplorer/TransactionsTable.tsx → ...xplorer/_components/TransactionsTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...nextjs/components/blockexplorer/index.tsx → ...s/app/blockexplorer/_components/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export * from "./AddressCodeTab"; | ||
export * from "./AddressLogsTab"; | ||
export * from "./AddressStorageTab"; | ||
export * from "./PaginationButton"; | ||
export * from "./SearchBar"; | ||
export * from "./BackButton"; | ||
export * from "./AddressCodeTab"; | ||
export * from "./TransactionHash"; | ||
export * from "./ContractTabs"; | ||
export * from "./PaginationButton"; | ||
export * from "./TransactionsTable"; |
93 changes: 93 additions & 0 deletions
93
templates/base/packages/nextjs/app/blockexplorer/address/[address]/page.tsx.template.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { withDefaults } from "../../../../../../../utils.js"; | ||
|
||
const contents = ({ chainName, artifactsDirName }) => ` | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { ${chainName[0]} } from "viem/chains"; | ||
import { AddressComponent } from "~~/app/blockexplorer/_components/AddressComponent"; | ||
import deployedContracts from "~~/contracts/deployedContracts"; | ||
import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; | ||
type PageProps = { | ||
params: { address: string }; | ||
}; | ||
async function fetchByteCodeAndAssembly(buildInfoDirectory: string, contractPath: string) { | ||
const buildInfoFiles = fs.readdirSync(buildInfoDirectory); | ||
let bytecode = ""; | ||
let assembly = ""; | ||
for (let i = 0; i < buildInfoFiles.length; i++) { | ||
const filePath = path.join(buildInfoDirectory, buildInfoFiles[i]); | ||
const buildInfo = JSON.parse(fs.readFileSync(filePath, "utf8")); | ||
if (buildInfo.output.contracts[contractPath]) { | ||
for (const contract in buildInfo.output.contracts[contractPath]) { | ||
bytecode = buildInfo.output.contracts[contractPath][contract].evm.bytecode.object; | ||
assembly = buildInfo.output.contracts[contractPath][contract].evm.bytecode.opcodes; | ||
break; | ||
} | ||
} | ||
if (bytecode && assembly) { | ||
break; | ||
} | ||
} | ||
return { bytecode, assembly }; | ||
} | ||
const getContractData = async (address: string) => { | ||
const contracts = deployedContracts as GenericContractsDeclaration | null; | ||
const chainId = ${chainName[0]}.id; | ||
let contractPath = ""; | ||
const buildInfoDirectory = path.join( | ||
__dirname, | ||
"..", | ||
"..", | ||
"..", | ||
"..", | ||
"..", | ||
"..", | ||
"..", | ||
"${chainName[0]}", | ||
"${artifactsDirName[0]}", | ||
"build-info", | ||
); | ||
if (!fs.existsSync(buildInfoDirectory)) { | ||
throw new Error(\`Directory \${buildInfoDirectory} not found.\`); | ||
} | ||
const deployedContractsOnChain = contracts ? contracts[chainId] : {}; | ||
for (const [contractName, contractInfo] of Object.entries(deployedContractsOnChain)) { | ||
if (contractInfo.address.toLowerCase() === address) { | ||
contractPath = \`contracts/\${contractName}.sol\`; | ||
break; | ||
} | ||
} | ||
if (!contractPath) { | ||
// No contract found at this address | ||
return null; | ||
} | ||
const { bytecode, assembly } = await fetchByteCodeAndAssembly(buildInfoDirectory, contractPath); | ||
return { bytecode, assembly }; | ||
}; | ||
const AddressPage = async ({ params }: PageProps) => { | ||
const address = params?.address as string; | ||
const contractData: { bytecode: string; assembly: string } | null = await getContractData(address); | ||
return <AddressComponent address={address} contractData={contractData} />; | ||
}; | ||
export default AddressPage;`; | ||
|
||
export default withDefaults(contents, { | ||
chainName: "hardhat", | ||
artifactsDirName: "artifacts", | ||
}); |
12 changes: 12 additions & 0 deletions
12
templates/base/packages/nextjs/app/blockexplorer/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getMetadata } from "~~/utils/scaffold-eth/getMetadata"; | ||
|
||
export const metadata = getMetadata({ | ||
title: "Block Explorer", | ||
description: "Block Explorer created with 🏗 Scaffold-ETH 2", | ||
}); | ||
|
||
const BlockExplorerLayout = ({ children }: { children: React.ReactNode }) => { | ||
return <>{children}</>; | ||
}; | ||
|
||
export default BlockExplorerLayout; |
6 changes: 3 additions & 3 deletions
6
...ages/nextjs/pages/blockexplorer/index.tsx → ...ackages/nextjs/app/blockexplorer/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.