From 895802104f6f38839a94a11bd1cca63a3c7f9604 Mon Sep 17 00:00:00 2001 From: port <108868128+portdeveloper@users.noreply.github.com> Date: Mon, 16 Sep 2024 06:47:23 +0300 Subject: [PATCH] Use the type Address in abi.ts and useFetchContractAbi --- packages/nextjs/hooks/useFetchContractAbi.ts | 4 ++-- packages/nextjs/utils/abi.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/nextjs/hooks/useFetchContractAbi.ts b/packages/nextjs/hooks/useFetchContractAbi.ts index 3e4a0cce..42198597 100644 --- a/packages/nextjs/hooks/useFetchContractAbi.ts +++ b/packages/nextjs/hooks/useFetchContractAbi.ts @@ -1,6 +1,6 @@ import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; -import { isAddress } from "viem"; +import { Address, isAddress } from "viem"; import { UsePublicClientReturnType } from "wagmi"; import { fetchContractABIFromEtherscan } from "~~/utils/abi"; @@ -19,7 +19,7 @@ const useFetchContractAbi = ({ contractAddress, chainId, disabled = false }: Fet throw new Error("Invalid contract address"); } - const addressToUse: string = contractAddress; + const addressToUse: Address = contractAddress; try { const { abi, implementation } = await fetchContractABIFromEtherscan(addressToUse, chainId); diff --git a/packages/nextjs/utils/abi.ts b/packages/nextjs/utils/abi.ts index 3d6eace2..c8517855 100644 --- a/packages/nextjs/utils/abi.ts +++ b/packages/nextjs/utils/abi.ts @@ -1,3 +1,4 @@ +import { Address } from "viem"; import * as chains from "viem/chains"; const findChainById = (chainId: number): chains.Chain => { @@ -32,7 +33,7 @@ const getEtherscanApiKey = (chainId: number): string => { return apiKey || ""; }; -export const fetchContractABIFromEtherscan = async (verifiedContractAddress: string, chainId: number) => { +export const fetchContractABIFromEtherscan = async (verifiedContractAddress: Address, chainId: number) => { const chain = findChainById(chainId); if (!chain || !chain.blockExplorers?.default?.apiUrl) {