"use client"; import { useEffect, useState } from "react"; import { Address, createPublicClient, http, toHex } from "viem"; import { hardhat } from "viem/chains"; const publicClient = createPublicClient({ chain: hardhat, transport: http(), }); export const AddressStorageTab = ({ address }: { address: Address }) => { const [storage, setStorage] = useState([]); useEffect(() => { const fetchStorage = async () => { try { const storageData = []; let idx = 0; while (true) { const storageAtPosition = await publicClient.getStorageAt({ address: address, slot: toHex(idx), }); if (storageAtPosition === "0x" + "0".repeat(64)) break; if (storageAtPosition) { storageData.push(storageAtPosition); } idx++; } setStorage(storageData); } catch (error) { console.error("Failed to fetch storage:", error); } }; fetchStorage(); }, [address]); return (
{storage.length > 0 ? (
            {storage.map((data, i) => (
              
Storage Slot {i}: {data}
))}
) : (
This contract does not have any variables.
)}
); };