I've integrated wagmi into my NFT project with React TypeScript.
While working on the NFT checking module, I encountered the following error:
Type 'string' is not assignable to type '
0x${string}
'
How can I convert my string into 0x${string}
?
Here's a snippet of my code:
import { useEffect, useState } from "react";
import { useContractRead, erc721ABI } from "wagmi";
const useNFTChecker = ({
contractAddress,
walletAddress,
}: {
contractAddress: string;///<-- this needs conversion
walletAddress: string;
}) => {
const { data, error } = useContractRead({
address: contractAddress, ///<-- `0x${string}`
contractInterface: erc721ABI,
functionName: "balanceOf",
args: [walletAddress],
});
const [hasNFT, setHasNFT] = useState(false);
...
return { hasNFT, error };
};
export default useNFTChecker;