API ReferenceReact provider and hooksFunction
useCreateLOCWorkflow()
function useCreateLOCWorkflow(): UseCreateLOCWorkflowResult;Headless create-LOC orchestration using the canonical workflow-hook envelope. The hook delegates
domain validation and workflow construction to sdk.loc; it performs no oracle fetch itself.
A dynamic LOC whose priceUpdate is omitted opts into automatic oracle resolution at final
transaction construction — this hook only; the core builders keep their network-free omission
behavior.
Returns
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 CreateStaticLOCButton() { const { prepareWorkflow, issues, isPreparing, error } = useCreateLOCWorkflow();
async function onSubmit() { // Validates first (no wallet prompt); builds the workflow only if // valid. const result = await prepareWorkflow({ kind: 'static', // collateral token == credited token, no oracle beneficiary: '0x1111111111111111111111111111111111111111', // 1,000 USDC (6 decimals): face value and, for a static LOC, // collateral. tokenAmount: { tokenAddress: testnetProfile.contracts.USDC.address, amount: 1_000_000_000n, }, expirationTimestampSeconds: BigInt( Math.floor(Date.now() / 1000) + 86400 * 30 ), }); if (result.status !== 'prepared') return;
// Deposit, approve, create -- each step prompts the wallet as needed. const execution = await result.workflow.execute(); if (execution.status === 'executed') { console.log(execution.operations.map(operation => operation.status)); } }
return ( <> <button onClick={onSubmit} disabled={isPreparing}> Create LOC </button> {issues.map(issue => ( <p key={issue.field}>{issue.message}</p> ))} {error && <p>{error.message}</p>} </> );}