Skip to main content
The useSorobanForm hook bridges the gap between smart contracts and user interfaces. It wraps react-hook-form and automatically generates a Zod validation schema based on your contract’s WASM specification.

Core Features

  • Runtime Validation: Fetches your contract’s spec and builds a Zod schema for the specific method you are calling.
  • Zero Configuration: You do not need to manually write Zod objects or TypeScript interfaces for your form fields.
  • Async Resolution: Since the schema is derived from the blockchain, the hook handles the asynchronous loading of the validation rules internally.
  • Standard Integration: Returns a standard useForm object, making it compatible with existing UI libraries like shadcn/ui or MUI.
react-hook-form and @hookform/resolvers are peer dependencies. This package does not bundle its own copy, so your app controls their versions.

Basic Usage

Handling BigInt Values

Stellar and Soroban frequently use 64-bit, 128-bit, or 256-bit integers for token amounts. Since HTML inputs always return strings, you must convert these values to bigint for validation to pass.
  • Use the setValueAs property within the register function.
  • This ensures the string input is transformed into a bigint before the Zod schema runs its check, avoiding precision loss from standard JavaScript numbers.

Integration with useContractSend

useSorobanForm and useContractSend are designed to work together:
  • Form layer (useSorobanForm): Validates that an address is well-formatted and that an amount is a valid number.
  • Action layer (useContractSend): Takes the validated data and handles simulation, signing, and submission.
  • Shared cache: Both hooks use the same contract spec cache, so there are no redundant network requests.

Parameters

Return Value

A full UseFormReturn object from react-hook-form. The properties you’ll use most: