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 sdk from "@onflow/sdk"
_10
_10
sdk.build(fns)

Or import directly the specific function:


_10
import { build } from "@onflow/sdk"
_10
_10
build(fns)

Usage


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

Parameters

fns (optional)

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

Returns

Promise<Interaction>


Rate this page