import { useState } from "react"; import { toast } from "react-toastify"; import { formatEther, isHash, type Hash } from "viem"; import { useTransaction } from "wagmi"; export function HomePage() { const [inputHash, setInputHash] = useState(''); const [confirmedHash, setConfirmedHash] = useState(undefined); const { data: transaction, isPending, error } = useTransaction({ hash: confirmedHash, query: { retry: 1 } }) function onSubmit(e) { e.preventDefault(); if (isHash(inputHash)) { setConfirmedHash(inputHash); } else { toast.error('Enter a valid transaction hash!'); } } return (

Transaction Explorer

Enter a transaction hash to get more details...

{ setInputHash(e.target.value); if (confirmedHash) { setConfirmedHash(undefined); } }} className="w-full border border-gray-300 p-2 rounded-lg" placeholder="Enter hash..." />
{!!confirmedHash && (

Details

{error &&

An error occurred. Please enter a valid hash.

} {isPending &&

Loading details...

} {!!transaction && (
Hash
{transaction.hash}
From
{transaction.from}
To
{transaction.to || 'N/A'}
Value
{formatEther(transaction.value)} ETH
)}
)}
); }