Skip to content

useWaitForTransaction

Waits for a transaction to be confirmed. You can specify the number of confirmations, max attempts, and polling interval.

Import

ts
import { useWaitForTransaction } from '@midl/react';

Example

tsx
function MyComponent() {
    const { waitForTransaction, data } = useWaitForTransaction();

    return (
        <div>
            <button onClick={() => waitForTransaction({ txId: 'f5b1a7d749f4f3e7b3f3e1e4d...', confirmations: 3 })}>
                Wait for transaction
            </button>
            <p>Confirmations: {data}</p>
        </div>
    );
}

Parameters

NameTypeDescription
mutationUseMutationOptions(optional) Mutation options for react-query.
configConfig(optional) Custom config to override the default from context.

WaitForTransactionVariables

NameTypeDescription
txIdstringThe transaction ID to wait for.
confirmationsnumber(optional) Number of confirmations to wait for (default: 1).
maxAttemptsnumber(optional) Maximum number of attempts to check for confirmation.
intervalMsnumber(optional) Interval in ms between attempts to check for confirmation.

Returns

NameTypeDescription
waitForTransaction(variables: WaitForTransactionVariables) => voidFunction to initiate waiting for a transaction.
waitForTransactionAsync(variables: WaitForTransactionVariables) => Promise<number>Function to asynchronously wait for a transaction.
...restobjectAdditional mutation state (e.g. isLoading, error, etc.).