Skip to main content

build

A builder function that creates an interaction from an array of builder functions.

The build function takes an array of builder functions and applies them to create a complete interaction object. This is the foundation for constructing all interactions in Flow, whether they're scripts, transactions, or queries.

Each builder function modifies specific parts of the interaction object, such as adding Cadence code, arguments, authorization details, or other configuration.

Import

You can import the entire package and access the function:


_10
import * as fcl from '@onflow/fcl';
_10
_10
fcl.build(fns);

Or import directly the specific function:


_10
import { build } from '@onflow/fcl';
_10
_10
build(fns);

Usage


_27
import * as fcl from '@onflow/fcl';
_27
_27
// Build a script interaction
_27
const scriptInteraction = await fcl.build([
_27
fcl.script`
_27
access(all) fun main(a: Int, b: Int): Int {
_27
return a + b
_27
}
_27
`,
_27
fcl.args([fcl.arg(1, fcl.t.Int), fcl.arg(2, fcl.t.Int)]),
_27
]);
_27
_27
// Build a transaction interaction
_27
const txInteraction = await fcl.build([
_27
fcl.transaction`
_27
transaction(name: String) {
_27
prepare(account: AuthAccount) {
_27
log("Hello, " + name)
_27
}
_27
}
_27
`,
_27
fcl.args([fcl.arg('World', fcl.t.String)]),
_27
fcl.proposer(proposerAuthz),
_27
fcl.payer(payerAuthz),
_27
fcl.authorizations([authorizerAuthz]),
_27
fcl.limit(100),
_27
]);

Parameters

fns (optional)

  • Type: (false | InteractionBuilderFn)[]
  • Description: The functions to apply to the interaction

Returns

Promise<Interaction>

A promise of an interaction


Rate this page