validator
A builder function that adds a validator to a transaction.
Validators are functions that run during transaction building to check for invalid configurations or parameters. They help catch errors early before submitting transactions to the network, preventing failed transactions and wasted compute costs.
Import
You can import the entire package and access the function:
_10import * as fcl from '@onflow/fcl';_10_10fcl.validator(cb);
Or import directly the specific function:
_10import { validator } from '@onflow/fcl';_10_10validator(cb);
Usage
_21import * as fcl from '@onflow/fcl';_21_21// Custom validator to ensure account has sufficient balance_21const validateBalance = (ix) => {_21  if (ix.message.computeLimit > 1000) {_21    throw new Error('Compute limit too high for this account');_21  }_21  return ix;_21};_21_21await fcl.send([_21  fcl.transaction`_21    transaction {_21      prepare(account: AuthAccount) {_21        // Transaction logic_21      }_21    }_21  `,_21  fcl.validator(validateBalance),_21  fcl.limit(500), // This will pass validation_21]);
Parameters
cb
- Type: 
Function - Description: The validator function that takes an interaction and returns it (or throws an error if invalid)
 
Returns
_10export type InteractionBuilderFn = (_10  ix: Interaction,_10) => Interaction | Promise<Interaction>;
A function that processes an interaction object