diff --git a/templates/base/packages/nextjs/app/debug/_components/contract/ContractUI.tsx b/templates/base/packages/nextjs/app/debug/_components/contract/ContractUI.tsx index 8fcec9d38..4d770ec28 100644 --- a/templates/base/packages/nextjs/app/debug/_components/contract/ContractUI.tsx +++ b/templates/base/packages/nextjs/app/debug/_components/contract/ContractUI.tsx @@ -21,7 +21,7 @@ type ContractUIProps = { export const ContractUI = ({ contractName, className = "" }: ContractUIProps) => { const [refreshDisplayVariables, triggerRefreshDisplayVariables] = useReducer(value => !value, false); const { targetNetwork } = useTargetNetwork(); - const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo(contractName); + const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo({ contractName }); const networkColor = useNetworkColor(); if (deployedContractLoading) { diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/index.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/index.ts index 084ccc852..05450b260 100644 --- a/templates/base/packages/nextjs/hooks/scaffold-eth/index.ts +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/index.ts @@ -13,3 +13,4 @@ export * from "./useScaffoldWriteContract"; export * from "./useTargetNetwork"; export * from "./useTransactor"; export * from "./useWatchBalance"; +export * from "./useSelectedNetwork"; diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/useDeployedContractInfo.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/useDeployedContractInfo.ts index 8f649c38a..0973af21d 100644 --- a/templates/base/packages/nextjs/hooks/scaffold-eth/useDeployedContractInfo.ts +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/useDeployedContractInfo.ts @@ -1,19 +1,29 @@ import { useEffect, useState } from "react"; -import { useTargetNetwork } from "./useTargetNetwork"; import { useIsMounted } from "usehooks-ts"; import { usePublicClient } from "wagmi"; -import { Contract, ContractCodeStatus, ContractName, contracts } from "~~/utils/scaffold-eth/contract"; +import { useSelectedNetwork } from "~~/hooks/scaffold-eth"; +import { + Contract, + ContractCodeStatus, + ContractName, + UseDeployedContractConfig, + contracts, +} from "~~/utils/scaffold-eth/contract"; /** * Gets the matching contract info for the provided contract name from the contracts present in deployedContracts.ts * and externalContracts.ts corresponding to targetNetworks configured in scaffold.config.ts */ -export const useDeployedContractInfo = (contractName: TContractName) => { +export const useDeployedContractInfo = ({ + contractName, + chainId, +}: UseDeployedContractConfig) => { const isMounted = useIsMounted(); - const { targetNetwork } = useTargetNetwork(); - const deployedContract = contracts?.[targetNetwork.id]?.[contractName as ContractName] as Contract; + + const selectedNetwork = useSelectedNetwork(chainId); + const deployedContract = contracts?.[selectedNetwork.id]?.[contractName as ContractName] as Contract; const [status, setStatus] = useState(ContractCodeStatus.LOADING); - const publicClient = usePublicClient({ chainId: targetNetwork.id }); + const publicClient = usePublicClient({ chainId: selectedNetwork.id }); useEffect(() => { const checkContractDeployment = async () => { diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/useNetworkColor.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/useNetworkColor.ts index ec9c77060..96d1958a1 100644 --- a/templates/base/packages/nextjs/hooks/scaffold-eth/useNetworkColor.ts +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/useNetworkColor.ts @@ -1,6 +1,7 @@ import { useTargetNetwork } from "./useTargetNetwork"; import { useTheme } from "next-themes"; -import { ChainWithAttributes } from "~~/utils/scaffold-eth"; +import { useSelectedNetwork } from "~~/hooks/scaffold-eth"; +import { AllowedChainIds, ChainWithAttributes } from "~~/utils/scaffold-eth"; export const DEFAULT_NETWORK_COLOR: [string, string] = ["#666666", "#bbbbbb"]; @@ -12,11 +13,11 @@ export function getNetworkColor(network: ChainWithAttributes, isDarkMode: boolea /** * Gets the color of the target network */ -export const useNetworkColor = () => { +export const useNetworkColor = (chainId?: AllowedChainIds) => { const { resolvedTheme } = useTheme(); - const { targetNetwork } = useTargetNetwork(); + const chain = useSelectedNetwork(chainId); const isDarkMode = resolvedTheme === "dark"; - return getNetworkColor(targetNetwork, isDarkMode); + return getNetworkColor(chain, isDarkMode); }; diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts index 1add8cba8..d814b230c 100644 --- a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts @@ -1,8 +1,9 @@ -import { useTargetNetwork } from "./useTargetNetwork"; import { Account, Address, Chain, Client, Transport, getContract } from "viem"; import { usePublicClient } from "wagmi"; import { GetWalletClientReturnType } from "wagmi/actions"; +import { useSelectedNetwork } from "~~/hooks/scaffold-eth"; import { useDeployedContractInfo } from "~~/hooks/scaffold-eth"; +import { AllowedChainIds } from "~~/utils/scaffold-eth"; import { Contract, ContractName } from "~~/utils/scaffold-eth/contract"; /** @@ -11,6 +12,7 @@ import { Contract, ContractName } from "~~/utils/scaffold-eth/contract"; * @param config - The config settings for the hook * @param config.contractName - deployed contract name * @param config.walletClient - optional walletClient from wagmi useWalletClient hook can be passed for doing write transactions + * @param config.chainId - optional chainId that is configured with the scaffold project to make use for multi-chain interactions. */ export const useScaffoldContract = < TContractName extends ContractName, @@ -18,13 +20,19 @@ export const useScaffoldContract = < >({ contractName, walletClient, + chainId, }: { contractName: TContractName; walletClient?: TWalletClient | null; + chainId?: AllowedChainIds; }) => { - const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo(contractName); - const { targetNetwork } = useTargetNetwork(); - const publicClient = usePublicClient({ chainId: targetNetwork.id }); + const selectedNetwork = useSelectedNetwork(chainId); + const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo({ + contractName, + chainId: selectedNetwork?.id as AllowedChainIds, + }); + + const publicClient = usePublicClient({ chainId: selectedNetwork?.id }); let contract = undefined; if (deployedContractData && publicClient) { diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts index 2477a9b20..80914f5dc 100644 --- a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts @@ -1,10 +1,11 @@ import { useEffect, useState } from "react"; -import { useTargetNetwork } from "./useTargetNetwork"; import { useInfiniteQuery } from "@tanstack/react-query"; import { Abi, AbiEvent, ExtractAbiEventNames } from "abitype"; import { BlockNumber, GetLogsParameters } from "viem"; import { Config, UsePublicClientReturnType, useBlockNumber, usePublicClient } from "wagmi"; +import { useSelectedNetwork } from "~~/hooks/scaffold-eth"; import { useDeployedContractInfo } from "~~/hooks/scaffold-eth"; +import { AllowedChainIds } from "~~/utils/scaffold-eth"; import { replacer } from "~~/utils/scaffold-eth/common"; import { ContractAbi, @@ -57,6 +58,7 @@ const getEvents = async ( * @param config.contractName - deployed contract name * @param config.eventName - name of the event to listen for * @param config.fromBlock - the block number to start reading events from + * @param config.chainId - optional chainId that is configured with the scaffold project to make use for multi-chain interactions. * @param config.filters - filters to be applied to the event (parameterName: value) * @param config.blockData - if set to true it will return the block data for each event (default: false) * @param config.transactionData - if set to true it will return the transaction data for each event (default: false) @@ -74,6 +76,7 @@ export const useScaffoldEventHistory = < contractName, eventName, fromBlock, + chainId, filters, blockData, transactionData, @@ -81,15 +84,19 @@ export const useScaffoldEventHistory = < watch, enabled = true, }: UseScaffoldEventHistoryConfig) => { - const { targetNetwork } = useTargetNetwork(); + const selectedNetwork = useSelectedNetwork(chainId); + const publicClient = usePublicClient({ - chainId: targetNetwork.id, + chainId: selectedNetwork.id, }); const [isFirstRender, setIsFirstRender] = useState(true); - const { data: blockNumber } = useBlockNumber({ watch: watch, chainId: targetNetwork.id }); + const { data: blockNumber } = useBlockNumber({ watch: watch, chainId: selectedNetwork.id }); - const { data: deployedContractData } = useDeployedContractInfo(contractName); + const { data: deployedContractData } = useDeployedContractInfo({ + contractName, + chainId: selectedNetwork.id as AllowedChainIds, + }); const event = deployedContractData && @@ -105,7 +112,7 @@ export const useScaffoldEventHistory = < address: deployedContractData?.address, eventName, fromBlock: fromBlock.toString(), - chainId: targetNetwork.id, + chainId: selectedNetwork.id, filters: JSON.stringify(filters, replacer), }, ], @@ -121,8 +128,18 @@ export const useScaffoldEventHistory = < }, enabled: enabled && isContractAddressAndClientReady, initialPageParam: fromBlock, - getNextPageParam: () => { - return blockNumber; + getNextPageParam: (lastPage, allPages, lastPageParam) => { + if (!blockNumber || fromBlock >= blockNumber) return undefined; + + const lastPageHighestBlock = Math.max( + Number(fromBlock), + ...(lastPage || []).map(event => Number(event.blockNumber || 0)), + ); + const nextBlock = BigInt(Math.max(Number(lastPageParam), lastPageHighestBlock) + 1); + + if (nextBlock > blockNumber) return undefined; + + return nextBlock; }, select: data => { const events = data.pages.flat(); @@ -133,6 +150,7 @@ export const useScaffoldEventHistory = < TTransactionData, TReceiptData >; + return { pages: eventHistoryData?.reverse(), pageParams: data.pageParams, diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldReadContract.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldReadContract.ts index 9d9e8f031..82dfe3dc9 100644 --- a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldReadContract.ts +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldReadContract.ts @@ -1,10 +1,11 @@ import { useEffect } from "react"; -import { useTargetNetwork } from "./useTargetNetwork"; import { QueryObserverResult, RefetchOptions, useQueryClient } from "@tanstack/react-query"; import type { ExtractAbiFunctionNames } from "abitype"; import { ReadContractErrorType } from "viem"; import { useBlockNumber, useReadContract } from "wagmi"; +import { useSelectedNetwork } from "~~/hooks/scaffold-eth"; import { useDeployedContractInfo } from "~~/hooks/scaffold-eth"; +import { AllowedChainIds } from "~~/utils/scaffold-eth"; import { AbiFunctionReturnType, ContractAbi, @@ -19,6 +20,7 @@ import { * @param config.contractName - deployed contract name * @param config.functionName - name of the function to be called * @param config.args - args to be passed to the function call + * @param config.chainId - optional chainId that is configured with the scaffold project to make use for multi-chain interactions. */ export const useScaffoldReadContract = < TContractName extends ContractName, @@ -27,16 +29,21 @@ export const useScaffoldReadContract = < contractName, functionName, args, + chainId, ...readConfig }: UseScaffoldReadConfig) => { - const { data: deployedContract } = useDeployedContractInfo(contractName); - const { targetNetwork } = useTargetNetwork(); + const selectedNetwork = useSelectedNetwork(chainId); + const { data: deployedContract } = useDeployedContractInfo({ + contractName, + chainId: selectedNetwork.id as AllowedChainIds, + }); + const { query: queryOptions, watch, ...readContractConfig } = readConfig; // set watch to true by default const defaultWatch = watch ?? true; const readContractHookRes = useReadContract({ - chainId: targetNetwork.id, + chainId: selectedNetwork.id, functionName, address: deployedContract?.address, abi: deployedContract?.abi, @@ -56,7 +63,7 @@ export const useScaffoldReadContract = < const queryClient = useQueryClient(); const { data: blockNumber } = useBlockNumber({ watch: defaultWatch, - chainId: targetNetwork.id, + chainId: selectedNetwork.id, query: { enabled: defaultWatch, }, diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWatchContractEvent.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWatchContractEvent.ts index 844b4a08b..26878a5ce 100644 --- a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWatchContractEvent.ts +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWatchContractEvent.ts @@ -1,8 +1,9 @@ -import { useTargetNetwork } from "./useTargetNetwork"; import { Abi, ExtractAbiEventNames } from "abitype"; import { Log } from "viem"; import { useWatchContractEvent } from "wagmi"; +import { useSelectedNetwork } from "~~/hooks/scaffold-eth"; import { addIndexedArgsToEvent, useDeployedContractInfo } from "~~/hooks/scaffold-eth"; +import { AllowedChainIds } from "~~/utils/scaffold-eth"; import { ContractAbi, ContractName, UseScaffoldEventConfig } from "~~/utils/scaffold-eth/contract"; /** @@ -11,6 +12,7 @@ import { ContractAbi, ContractName, UseScaffoldEventConfig } from "~~/utils/scaf * @param config - The config settings * @param config.contractName - deployed contract name * @param config.eventName - name of the event to listen for + * @param config.chainId - optional chainId that is configured with the scaffold project to make use for multi-chain interactions. * @param config.onLogs - the callback that receives events. */ export const useScaffoldWatchContractEvent = < @@ -19,10 +21,14 @@ export const useScaffoldWatchContractEvent = < >({ contractName, eventName, + chainId, onLogs, }: UseScaffoldEventConfig) => { - const { data: deployedContractData } = useDeployedContractInfo(contractName); - const { targetNetwork } = useTargetNetwork(); + const selectedNetwork = useSelectedNetwork(chainId); + const { data: deployedContractData } = useDeployedContractInfo({ + contractName, + chainId: selectedNetwork.id as AllowedChainIds, + }); const addIndexedArgsToLogs = (logs: Log[]) => logs.map(addIndexedArgsToEvent); const listenerWithIndexedArgs = (logs: Log[]) => onLogs(addIndexedArgsToLogs(logs) as Parameters[0]); @@ -30,7 +36,7 @@ export const useScaffoldWatchContractEvent = < return useWatchContractEvent({ address: deployedContractData?.address, abi: deployedContractData?.abi as Abi, - chainId: targetNetwork.id, + chainId: selectedNetwork.id, onLogs: listenerWithIndexedArgs, eventName, }); diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts index 4bd903f7f..f8454394b 100644 --- a/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts @@ -1,37 +1,44 @@ import { useState } from "react"; -import { useTargetNetwork } from "./useTargetNetwork"; import { MutateOptions } from "@tanstack/react-query"; import { Abi, ExtractAbiFunctionNames } from "abitype"; -import { Config, UseWriteContractParameters, useAccount, useWriteContract } from "wagmi"; +import { Config, useAccount, useWriteContract } from "wagmi"; import { WriteContractErrorType, WriteContractReturnType } from "wagmi/actions"; import { WriteContractVariables } from "wagmi/query"; +import { useSelectedNetwork } from "~~/hooks/scaffold-eth"; import { useDeployedContractInfo, useTransactor } from "~~/hooks/scaffold-eth"; -import { notification } from "~~/utils/scaffold-eth"; +import { AllowedChainIds, notification } from "~~/utils/scaffold-eth"; import { ContractAbi, ContractName, ScaffoldWriteContractOptions, ScaffoldWriteContractVariables, + UseScaffoldWriteConfig, } from "~~/utils/scaffold-eth/contract"; /** * Wrapper around wagmi's useWriteContract hook which automatically loads (by name) the contract ABI and address from * the contracts present in deployedContracts.ts & externalContracts.ts corresponding to targetNetworks configured in scaffold.config.ts * @param contractName - name of the contract to be written to + * @param config.chainId - optional chainId that is configured with the scaffold project to make use for multi-chain interactions. * @param writeContractParams - wagmi's useWriteContract parameters */ -export const useScaffoldWriteContract = ( - contractName: TContractName, - writeContractParams?: UseWriteContractParameters, -) => { - const { chain } = useAccount(); +export const useScaffoldWriteContract = ({ + contractName, + chainId, + writeContractParams, +}: UseScaffoldWriteConfig) => { + const { chain: accountChain } = useAccount(); const writeTx = useTransactor(); const [isMining, setIsMining] = useState(false); - const { targetNetwork } = useTargetNetwork(); const wagmiContractWrite = useWriteContract(writeContractParams); - const { data: deployedContractData } = useDeployedContractInfo(contractName); + const selectedNetwork = useSelectedNetwork(chainId); + + const { data: deployedContractData } = useDeployedContractInfo({ + contractName, + chainId: selectedNetwork.id as AllowedChainIds, + }); const sendContractWriteAsyncTx = async < TFunctionName extends ExtractAbiFunctionNames, "nonpayable" | "payable">, @@ -44,12 +51,13 @@ export const useScaffoldWriteContract = ( return; } - if (!chain?.id) { + if (!accountChain?.id) { notification.error("Please connect your wallet"); return; } - if (chain?.id !== targetNetwork.id) { - notification.error("You are on the wrong network"); + + if (accountChain?.id !== selectedNetwork.id) { + notification.error(`Wallet is connected to the wrong network. Please switch to ${selectedNetwork.name}`); return; } @@ -93,12 +101,13 @@ export const useScaffoldWriteContract = ( notification.error("Target Contract is not deployed, did you forget to run `yarn deploy`?"); return; } - if (!chain?.id) { + if (!accountChain?.id) { notification.error("Please connect your wallet"); return; } - if (chain?.id !== targetNetwork.id) { - notification.error("You are on the wrong network"); + + if (accountChain?.id !== selectedNetwork.id) { + notification.error(`Wallet is connected to the wrong network. Please switch to ${selectedNetwork.name}`); return; } diff --git a/templates/base/packages/nextjs/hooks/scaffold-eth/useSelectedNetwork.ts b/templates/base/packages/nextjs/hooks/scaffold-eth/useSelectedNetwork.ts new file mode 100644 index 000000000..93832ef4a --- /dev/null +++ b/templates/base/packages/nextjs/hooks/scaffold-eth/useSelectedNetwork.ts @@ -0,0 +1,8 @@ +import scaffoldConfig from "~~/scaffold.config"; +import { useGlobalState } from "~~/services/store/store"; +import { AllowedChainIds } from "~~/utils/scaffold-eth"; + +export function useSelectedNetwork(chainId?: AllowedChainIds) { + const targetNetwork = useGlobalState(({ targetNetwork }) => targetNetwork); + return scaffoldConfig.targetNetworks.find(targetNetwork => targetNetwork.id === chainId) ?? targetNetwork; +} diff --git a/templates/base/packages/nextjs/package.json b/templates/base/packages/nextjs/package.json index ad08902ef..bd878e05f 100644 --- a/templates/base/packages/nextjs/package.json +++ b/templates/base/packages/nextjs/package.json @@ -3,15 +3,15 @@ "private": true, "version": "0.1.0", "scripts": { - "dev": "next dev", - "start": "next dev", "build": "next build", - "serve": "next start", - "lint": "next lint", - "format": "prettier --write . '!(node_modules|.next|contracts)/**/*'", "check-types": "tsc --noEmit --incremental", - "vercel": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1", - "vercel:yolo": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1 --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true" + "dev": "next dev", + "format": "prettier --write . '!(node_modules|.next|contracts)/**/*'", + "lint": "next lint", + "serve": "next start", + "start": "next dev", + "vercel": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1 --build-env VERCEL_TELEMETRY_DISABLED=1", + "vercel:yolo": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1 --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true --build-env VERCEL_TELEMETRY_DISABLED=1" }, "dependencies": { "@heroicons/react": "~2.1.5", diff --git a/templates/base/packages/nextjs/utils/scaffold-eth/contract.ts b/templates/base/packages/nextjs/utils/scaffold-eth/contract.ts index b66f42a9b..70d1d4c32 100644 --- a/templates/base/packages/nextjs/utils/scaffold-eth/contract.ts +++ b/templates/base/packages/nextjs/utils/scaffold-eth/contract.ts @@ -1,3 +1,4 @@ +import { AllowedChainIds } from "./networks"; import { MutateOptions } from "@tanstack/react-query"; import { Abi, @@ -21,7 +22,7 @@ import { TransactionReceipt, WriteContractErrorType, } from "viem"; -import { Config, UseReadContractParameters, UseWatchContractEventParameters } from "wagmi"; +import { Config, UseReadContractParameters, UseWatchContractEventParameters, UseWriteContractParameters } from "wagmi"; import { WriteContractParameters, WriteContractReturnType } from "wagmi/actions"; import { WriteContractVariables } from "wagmi/query"; import deployedContractsData from "~~/contracts/deployedContracts"; @@ -166,11 +167,23 @@ type UseScaffoldArgsParam< args?: never; }; +export type UseDeployedContractConfig = { + contractName: TContractName; + chainId?: AllowedChainIds; +}; + +export type UseScaffoldWriteConfig = { + contractName: TContractName; + chainId?: AllowedChainIds; + writeContractParams?: UseWriteContractParameters; +}; + export type UseScaffoldReadConfig< TContractName extends ContractName, TFunctionName extends ExtractAbiFunctionNames, ReadAbiStateMutability>, > = { contractName: TContractName; + chainId?: AllowedChainIds; watch?: boolean; } & IsContractDeclarationMissing< Partial, @@ -216,6 +229,7 @@ export type UseScaffoldEventConfig< > = { contractName: TContractName; eventName: TEventName; + chainId?: AllowedChainIds; } & IsContractDeclarationMissing< Omit & { onLogs: ( @@ -275,6 +289,7 @@ export type UseScaffoldEventHistoryConfig< contractName: TContractName; eventName: IsContractDeclarationMissing; fromBlock: bigint; + chainId?: AllowedChainIds; filters?: EventFilters; blockData?: TBlockData; transactionData?: TTransactionData; @@ -297,7 +312,6 @@ export type UseScaffoldEventHistoryData< | IsContractDeclarationMissing< any[], { - log: Log; args: AbiParametersToPrimitiveTypes & GetEventArgs< ContractAbi, @@ -309,7 +323,7 @@ export type UseScaffoldEventHistoryData< blockData: TBlockData extends true ? Block : null; receiptData: TReceiptData extends true ? GetTransactionReturnType : null; transactionData: TTransactionData extends true ? GetTransactionReceiptReturnType : null; - }[] + } & Log[] > | undefined; diff --git a/templates/base/packages/nextjs/utils/scaffold-eth/networks.ts b/templates/base/packages/nextjs/utils/scaffold-eth/networks.ts index 96b779866..2a5802050 100644 --- a/templates/base/packages/nextjs/utils/scaffold-eth/networks.ts +++ b/templates/base/packages/nextjs/utils/scaffold-eth/networks.ts @@ -10,6 +10,7 @@ type ChainAttributes = { }; export type ChainWithAttributes = chains.Chain & Partial; +export type AllowedChainIds = (typeof scaffoldConfig.targetNetworks)[number]["id"]; // Mapping of chainId to RPC chain name an format followed by alchemy and infura export const RPC_CHAIN_NAMES: Record = { diff --git a/templates/solidity-frameworks/foundry/package.json b/templates/solidity-frameworks/foundry/package.json index cb202038f..ab69202ee 100644 --- a/templates/solidity-frameworks/foundry/package.json +++ b/templates/solidity-frameworks/foundry/package.json @@ -1,20 +1,30 @@ { "scripts": { - "account": "yarn workspace @se-2/foundry account", - "fork": "yarn workspace @se-2/foundry fork", - "compile": "yarn workspace @se-2/foundry compile", - "chain": "yarn workspace @se-2/foundry chain", - "deploy": "yarn workspace @se-2/foundry deploy", - "deploy:verify": "yarn workspace @se-2/foundry deploy:verify", - "account:generate": "yarn workspace @se-2/foundry account:generate", - "account:import": "yarn workspace @se-2/foundry account:import", + "account": "yarn foundry:account", + "account:generate": "yarn foundry:generate", + "account:import": "yarn foundry:account-import", + "chain": "yarn foundry:chain", + "compile": "yarn foundry:compile", + "deploy": "yarn foundry:deploy", + "deploy:verify": "yarn foundry:deploy-verify", + "fork": "yarn foundry:fork", + "format": "yarn next:format && yarn foundry:format", + "foundry:account": "yarn workspace @se-2/foundry account", + "foundry:account-import": "yarn workspace @se-2/foundry account:import", + "foundry:chain": "yarn workspace @se-2/foundry chain", + "foundry:compile": "yarn workspace @se-2/foundry compile", + "foundry:deploy": "yarn workspace @se-2/foundry deploy", + "foundry:deploy-verify": "yarn workspace @se-2/foundry deploy:verify", + "foundry:flatten": "yarn workspace @se-2/foundry flatten", + "foundry:fork": "yarn workspace @se-2/foundry fork", + "foundry:format": "yarn workspace @se-2/foundry format", + "foundry:generate": "yarn workspace @se-2/foundry account:generate", "foundry:lint": "yarn workspace @se-2/foundry lint", "foundry:test": "yarn workspace @se-2/foundry test", - "foundry:format": "yarn workspace @se-2/foundry format", + "foundry:verify": "yarn workspace @se-2/foundry verify", + "generate": "yarn foundry:generate", + "lint": "yarn nextjs:lint && yarn foundry:lint", "test": "yarn foundry:test", - "verify": "yarn workspace @se-2/foundry verify", - "generate": "yarn account:generate", - "flatten": "yarn workspace @se-2/foundry flatten", - "format": "yarn next:format && yarn foundry:format" + "verify": "yarn foundry:verify" } } diff --git a/templates/solidity-frameworks/foundry/packages/foundry/package.json b/templates/solidity-frameworks/foundry/packages/foundry/package.json index 960366dc0..6e2ec8aad 100644 --- a/templates/solidity-frameworks/foundry/packages/foundry/package.json +++ b/templates/solidity-frameworks/foundry/packages/foundry/package.json @@ -3,21 +3,21 @@ "version": "0.0.1", "type": "module", "scripts": { - "verify-keystore": "make verify-keystore", - "account": "make account", - "account:generate": "make account-generate ACCOUNT_NAME=${1:-scaffold-eth-custom}", - "account:import": "make account-import ACCOUNT_NAME=${1:-scaffold-eth-custom}", - "chain": "make chain", - "compile": "make compile", - "deploy": "make build-and-deploy RPC_URL=${1:-localhost}", - "deploy:verify": "make deploy-verify RPC_URL=${1:-localhost}", - "flatten": "make flatten", - "fork": "make fork FORK_URL=${1:-mainnet}", - "format": "make format", - "lint": "make lint", - "test": "make test", - "verify": "make build-and-verify RPC_URL=${1:-localhost}", - "postinstall": "shx cp -n .env.example .env" + "account": "make account", + "account:generate": "make account-generate ACCOUNT_NAME=${1:-scaffold-eth-custom}", + "account:import": "make account-import ACCOUNT_NAME=${1:-scaffold-eth-custom}", + "chain": "make chain", + "compile": "make compile", + "deploy": "make build-and-deploy RPC_URL=${1:-localhost}", + "deploy:verify": "make deploy-verify RPC_URL=${1:-localhost}", + "flatten": "make flatten", + "fork": "make fork FORK_URL=${1:-mainnet}", + "format": "make format", + "lint": "make lint", + "postinstall": "shx cp -n .env.example .env", + "test": "make test", + "verify": "make build-and-verify RPC_URL=${1:-localhost}", + "verify-keystore": "make verify-keystore" }, "dependencies": { "dotenv": "~16.3.1", diff --git a/templates/solidity-frameworks/hardhat/package.json b/templates/solidity-frameworks/hardhat/package.json index 6008de639..1c06bbb22 100644 --- a/templates/solidity-frameworks/hardhat/package.json +++ b/templates/solidity-frameworks/hardhat/package.json @@ -1,21 +1,30 @@ { "scripts": { - "account": "yarn workspace @se-2/hardhat account", + "account": "yarn hardhat:account", "account:import": "yarn workspace @se-2/hardhat account:import", "account:generate": "yarn workspace @se-2/hardhat account:generate", - "chain": "yarn workspace @se-2/hardhat chain", - "fork": "yarn workspace @se-2/hardhat fork", - "deploy": "yarn workspace @se-2/hardhat deploy", - "verify": "yarn workspace @se-2/hardhat verify", - "hardhat-verify": "yarn workspace @se-2/hardhat hardhat-verify", - "compile": "yarn workspace @se-2/hardhat compile", + "chain": "yarn hardhat:chain", + "compile": "yarn hardhat:compile", + "deploy": "yarn hardhat:deploy", + "fork": "yarn hardhat:fork", + "format": "yarn next:format && yarn hardhat:format", "generate": "yarn account:generate", + "hardhat:account": "yarn workspace @se-2/hardhat account", + "hardhat:chain": "yarn workspace @se-2/hardhat chain", + "hardhat:check-types": "yarn workspace @se-2/hardhat check-types", + "hardhat:compile": "yarn workspace @se-2/hardhat compile", + "hardhat:deploy": "yarn workspace @se-2/hardhat deploy", + "hardhat:flatten": "yarn workspace @se-2/hardhat flatten", + "hardhat:fork": "yarn workspace @se-2/hardhat fork", + "hardhat:format": "yarn workspace @se-2/hardhat format", + "hardhat:generate": "yarn workspace @se-2/hardhat generate", + "hardhat:hardhat-verify": "yarn workspace @se-2/hardhat hardhat-verify", "hardhat:lint": "yarn workspace @se-2/hardhat lint", "hardhat:lint-staged": "yarn workspace @se-2/hardhat lint-staged", - "hardhat:format": "yarn workspace @se-2/hardhat format", "hardhat:test": "yarn workspace @se-2/hardhat test", + "hardhat:verify": "yarn workspace @se-2/hardhat verify", + "lint": "yarn nextjs:lint && yarn hardhat:lint", "test": "yarn hardhat:test", - "flatten": "yarn workspace @se-2/hardhat flatten", - "format": "yarn next:format && yarn hardhat:format" + "verify": "yarn hardhat:verify" } } diff --git a/templates/solidity-frameworks/hardhat/packages/hardhat/package.json b/templates/solidity-frameworks/hardhat/packages/hardhat/package.json index 7d4faf652..59cf1d736 100644 --- a/templates/solidity-frameworks/hardhat/packages/hardhat/package.json +++ b/templates/solidity-frameworks/hardhat/packages/hardhat/package.json @@ -3,21 +3,21 @@ "version": "0.0.1", "scripts": { "account": "hardhat run scripts/listAccount.ts", - "account:import": "hardhat run scripts/importAccount.ts", "account:generate": "hardhat run scripts/generateAccount.ts", + "account:import": "hardhat run scripts/importAccount.ts", "chain": "hardhat node --network hardhat --no-deploy", "check-types": "tsc --noEmit --incremental", "compile": "hardhat compile", "deploy": "ts-node scripts/runHardhatDeployWithPK.ts", + "flatten": "hardhat flatten", "fork": "MAINNET_FORKING_ENABLED=true hardhat node --network hardhat --no-deploy", + "format": "prettier --write './**/*.(ts|sol)'", "generate": "yarn account:generate", - "flatten": "hardhat flatten", + "hardhat-verify": "hardhat verify", "lint": "eslint --config ./.eslintrc.json --ignore-path ./.eslintignore ./*.ts ./deploy/**/*.ts ./scripts/**/*.ts ./test/**/*.ts", "lint-staged": "eslint --config ./.eslintrc.json --ignore-path ./.eslintignore", - "format": "prettier --write './**/*.(ts|sol)'", "test": "REPORT_GAS=true hardhat test --network hardhat", - "verify": "hardhat etherscan-verify", - "hardhat-verify": "hardhat verify" + "verify": "hardhat etherscan-verify" }, "devDependencies": { "@ethersproject/abi": "~5.7.0",