React Hook - Use wait for transaction hash

Apr 30, 2021 · Dung Huynh

Context

When submitting transactions to Ethereum, you get a hash but need to poll for the receipt to know if it succeeded. Libraries like BlockNative exist but are paid. use-wait-for-transaction-hash provides a free hook using HTTP polling.

Usage

import { useWaitForTransactionHash } from 'use-wait-for-transaction-hash';

function TransactionStatus({ hash, providerUrl }: { hash: string; providerUrl: string }) {
  const { status } = useWaitForTransactionHash({ hash, providerUrl });

  return <div>Status: {status}</div>;
}

Returns: "pending""success" or "failed"

Demo & Docs