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:
_10import * as fcl from '@onflow/fcl';_10_10fcl.build(fns);
Or import directly the specific function:
_10import { build } from '@onflow/fcl';_10_10build(fns);
Usage
_27import * as fcl from '@onflow/fcl';_27_27// Build a script interaction_27const 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_27const 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
A promise of an interaction