Validation
Validate user input against rule sets before building a workflow, without throwing.
Validation happens before a wallet is ever involved. Invalid user input is data, not an exception:
rules return issues, while the single-value validators return a Result whose error side carries
ValidationError values from Errors. That
makes it safe to run against a half-filled form: a rule whose own required field is absent reports
FieldRequired for that field rather than being silently skipped, while a rule missing only a
foreign (non-required) dependency still defers silently.
runValidation (and
useIncrementalValidation’s validateAll)
give the exhaustive, submit-time check;
useIncrementalValidation’s per-keystroke
path is the separate incremental case, deferring a rule silently while its dependencies are still
incomplete.
runValidation takes a rule set — such as
createStaticLOCRules or
cancelLOCsRules, one per operation — together with
partial params, and returns every issue it finds; an empty array means valid.
getValidationErrorMessage turns an issue
into display text, and getErrorsByFieldPath
selects the issues for one field or a whole group. Below the rule sets,
validateAddress,
validateTag,
validateTokenAmount, and
validateNonEmpty check a single value directly.
Use defineValidationRule when authoring a rule.
Its callback can read required dependsOn fields and optional revalidateOn fields; any other read
is a rule-definition defect and throws with the undeclared field name. Read those fields
individually: key enumeration with Object.keys, Reflect.ownKeys, or object spread always throws
because absent undeclared fields would otherwise evade incremental watches. The structural
ValidationRule interface remains compatible with
existing external rule objects.
React applications drive per-field state from these same rule sets with
useIncrementalValidation — see
React hooks.
Checking a partly filled create-LOC form:
// Partial params are safe to call with: a rule whose own required field is// absent reports `FieldRequired` for that field instead of being silently// skipped, while a rule missing only a foreign (non-required) dependency// still defers silently. This draft deliberately omits the required// `expirationTimestampSeconds`, so that rule reports it instead of being// silently skipped. `tokenAmount` is well-formed here, so// `staticLOCCollateralRules`' async checks also run against live chain// state alongside it -- expect more than just the one field, and a// rejection instead of a resolved array without a connected wallet.const draft: Partial<CreateStaticLOCParams> = { beneficiary: '0x1111111111111111111111111111111111111111', tokenAmount: { tokenAddress: testnetProfile.contracts.USDC.address, amount: 250_000_000n, },};// The SDK instance is the SDKContext; async rules read chain and subgraph// state through it.const issues = await runValidation(sdk, createStaticLOCRules, draft);if (issues.length === 0) return 'ok';return issues.map(i => `${i.field}: ${getValidationErrorMessage(i)}`);Primary APIs
Run validation
runValidation— Runs a set of ValidationRules against (possibly partial) operation parameters, without touching a wallet.validateUserProvidedLOCConfig— Checks a LOCConfig for shape errors before it is handed to the SDK: every configured address and allowlist entry must be a valid Ethereum…
Author rules
defineValidationRule— Creates a validation rule whose callback can read only fields declared bydependsOnorrevalidateOn.ValidationRule— A validation rule declares a single validation concern: which fields must be present, which additional optional fields trigger…
Rule sets
cancelLOCRules— Validation rules for the cancelLOC operation.cancelLOCsRules— Validation for an atomic batch of LOC cancellations through Multicall.cancelLOCsAndWithdrawRules— Validation for the sequential Multicall cancellation + vault withdrawal path.createDynamicLOCRules— Validation rules for the createDynamicLOC operation.createStaticLOCRules— Validation rules for the createStaticLOC operation.depositToVaultRules— Validation rules for the depositToVault operation.erc20ApproveRules— Validation rules for the erc20Approve operation.extendLOCRules— Creator-authorized extension checked against the existing expiry and one chain clock.modifyLOCCollateralRules— Creator-authorized changes to reserved dynamic collateral.modifyVaultAllowanceSignatureRules— Validation rules for the modifyVaultAllowanceSignature operation.redeemLOCRules— Validation rules for the redeemLOC operation.vaultAllowanceRules— Validation rules for the vaultAllowance operation.withdrawFromVaultRules— Validation rules for the withdrawFromVault operation.cancelLOCAuthorizationRules— Pre-sign rules for a cancellation authorization definition.modifyVaultAllowanceAuthorizationRules— Pre-sign rules for a vault allowance authorization definition.redeemLOCAuthorizationRules— Pre-sign rules for a redemption authorization definition.vaultDepositAuthorizationRules— Pre-sign rules for a vault deposit authorization definition.invalidateVaultNoncesRules— Validation for the bounded, monotonic CollateralVault revocation call.
Single-value validators
validateAddress— Validates an Ethereum address string.validateTag— Validates that a LOC tag does not exceed the 512-byte on-chain limit.validateTokenAmount— Validates that a token amount is greater than zero.validateNonEmpty— Validates that a raw value is a non-empty string.
Supporting types and functions in this group are not listed here; each has its own page, listed with the group in the sidebar.