Skip to content

Validation

Check user input before a wallet is involved, without throwing.

Validation happens before a wallet is involved, and invalid input is data, not an exception. Each workflow method has a validate method beside it, such as sdk.loc.validateCreateStatic or sdk.vault.validateDeposit, that returns every problem it finds as a ValidationIssue. An empty array means the input is valid. It’s safe to run against a half-filled form: a required field that is still missing comes back as an issue for that field.

getValidationErrorMessage turns an issue into text you can show beside the field. Building a workflow doesn’t validate, and executing one always validates again against fresh chain state before the first wallet prompt.

React forms get the same checks field by field from useIncrementalValidation, a beta hook in React provider and hooks.

Checking a half-filled create form:

// A half-filled form is safe to check: each missing or invalid field
// comes back as an issue, and nothing throws.
const draft: Partial<CreateStaticLOCParams> = {
beneficiary: '0x1111111111111111111111111111111111111111',
tokenAmount: {
tokenAddress: testnetProfile.contracts.USDC.address,
amount: 250_000_000n,
},
};
const issues = await sdk.loc.validateCreateStatic(draft);
if (issues.length === 0) return 'ok';
return issues.map(i => `${i.field}: ${getValidationErrorMessage(i)}`);

Primary APIs

Functions

Interfaces

  • ValidationIssue — One problem validation found with an operation’s inputs, as a plain data object.