This example shows how to create a transaction manager component.
Transaction Manager
Submitted transactions will appear here.
Install dependencies
A transaction manager requires to persist state across several components. In
React, this is done by using a state management library such as
Jotai, Recoil (based on atoms) or
Redux.
For this demo, we are going to use Jotai.
npm
pnpm
yarn
_10
npm install jotai
Create the transaction manager hook
Next we can create a transaction manager hook. We want to persist the
transaction list across page reloads so we use Jotai's atomWithStorage
function to create the atom.
Instead of calling the writeAsync function directly, we are going to create a
wrapper function that sends the transaction and then adds it to our transaction
manager.
Finally, we create a component that fetches the transaction receipt and displays
its status.
This component uses the useWaitForTransaction hook to fetch the transaction
receipt. Notice that we use the watch flag to refresh the receipt at every
block, and the retry flag to retry fetching data on error. This is needed
because the RPC provider may return a "not found" error for a few seconds after
we submit our transaction.
components/transaction-status.tsx
_31
function TransactionStatus({ hash }: { hash: string }) {