Skip to content

API ReferenceTransactions, wallets, and signaturesFunction

awaitTransactionConfirmation()

function awaitTransactionConfirmation<T>(ctx, params, op): Promise<AwaitTransactionResponse<T>>;

Waits for the transaction with the provided hash to be mined and confirmed by the specified number of blocks, then wraps the result in an AwaitTransactionResponse that maps revert errors to typed operation errors.

Type Parameters

Type Parameter
T extends AnvilWalletOperationType

Parameters

ParameterTypeDescription
ctxSDKContextThe SDK context.
paramsAwaitTransactionConfirmationParamsThe necessary parameters to await the transaction.
opTThe operation type being awaited.

Returns

Promise<AwaitTransactionResponse<T>>

The AwaitTransactionResponse, containing the receipt or the parsed error(s) for the operation in question.

Example

// Every write follows build -> send -> await. Here: revoke the vault's
// USDC allowance.
const transaction = await buildERC20RevokeTransaction(sdk, {
erc20Address: USDC,
spender: await sdk.getContractAddress(AnvilContract.CollateralVault),
});
// Throws on wallet rejection, revert, or missing wallet.
const hash = await sendTransaction(sdk, { transaction });
const result = await awaitTransactionConfirmation(
sdk,
{ hash, confirmations: 2 },
AnvilWalletOperationType.ERC20Approve // selects the typed error below
);
if (result.error) throw new Error(JSON.stringify(result.error));
return result.receipt?.status === 'success';