Skip to content

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 by dependsOn or revalidateOn.
  • ValidationRule — A validation rule declares a single validation concern: which fields must be present, which additional optional fields trigger…

Rule sets

Single-value validators

Supporting types and functions in this group are not listed here; each has its own page, listed with the group in the sidebar.