API ReferenceReact provider and hooksFunction
useDepositToVaultWorkflow()
function useDepositToVaultWorkflow(): UseDepositToVaultWorkflowResult;Validates and prepares a CollateralVault deposit.
The prepared workflow adds an ERC-20 approval step when the vault’s allowance is short of the
deposit, so executing it may prompt the wallet more than once. Deposits land in the account’s
available balance.
Returns
UseDepositToVaultWorkflowResult
The canonical preparation envelope. validate reports a verdict without building anything;
prepareWorkflow validates and then builds, resolving to prepared, invalid, failed, or
cancelled; workflow, issues, error, and isPreparing mirror the latest request; and reset
discards it. No wallet is prompted until workflow.execute().
Throws
Error when rendered outside <AnvilProvider>, by way of useAnvilSDK. Nothing else
throws: a rejected validation or build is reported as a failed result, not as an exception.
Example
export function DepositButton() { const { prepareWorkflow, isPreparing } = useDepositToVaultWorkflow();
async function deposit() { // The prepared workflow adds an ERC-20 approval step when the vault's // allowance is short, so this may prompt the wallet twice. const result = await prepareWorkflow({ tokenAmounts: [{ tokenAddress: USDC, amount: 1_000_000_000n }], }); if (result.status === 'prepared') await result.workflow.execute(); }
return ( <button onClick={deposit} disabled={isPreparing}> Deposit 1,000 USDC </button> );}