Skip to content

Commit

Permalink
Use the type Address in abi.ts and useFetchContractAbi
Browse files Browse the repository at this point in the history
  • Loading branch information
portdeveloper committed Sep 16, 2024
1 parent 004065b commit 8958021
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/nextjs/hooks/useFetchContractAbi.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/utils/abi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Address } from "viem";
import * as chains from "viem/chains";

const findChainById = (chainId: number): chains.Chain => {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8958021

Please sign in to comment.