Skip to main content

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:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.validator(cb)

Or import directly the specific function:


_10
import { validator } from "@onflow/sdk"
_10
_10
validator(cb)

Usage


_21
import * as fcl from "@onflow/fcl";
_21
_21
// Custom validator to ensure account has sufficient balance
_21
const 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
_21
await 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

InteractionBuilderFn


_10
export type InteractionBuilderFn = (
_10
ix: Interaction
_10
) => Interaction | Promise<Interaction>


Rate this page