API ReferenceReact provider and hooksFunction
useWithdrawFromVaultWorkflow()
function useWithdrawFromVaultWorkflow(): UseWithdrawFromVaultWorkflowResult;Validates and prepares a CollateralVault withdrawal.
Only the account’s available balance is withdrawable; collateral reserved by any contract stays
locked until that reservation is released. Omitting withdrawalAmount withdraws the full available
balance, resolved at execution time. The vault deducts its withdrawal fee before transferring (see
useVaultWithdrawalFeeBasisPoints).
Returns
UseWithdrawFromVaultWorkflowResult
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 WithdrawAllButton() { const vault = useWithdrawFromVaultWorkflow();
// Only the `available` balance is withdrawable; reserved collateral // stays locked until its LOC releases it. const params = { tokenAddress: USDC };
async function check() { const verdict = await vault.validate(params); console.log(verdict.status); // 'valid' | 'invalid' | 'failed' | ... }
async function withdraw() { const result = await vault.prepareWorkflow(params); if (result.status === 'prepared') await result.workflow.execute(); }
return ( <> <button onClick={check}>Check</button> <button onClick={withdraw}>Withdraw all</button> {vault.issues.map(issue => ( <p key={issue.field}>{issue.message}</p> ))} </> );}