pipe
Async pipe function to compose interactions.
The pipe function is the foundation for composing multiple interaction builder functions together. It sequentially applies builder functions to an interaction, allowing for complex interaction construction. Each function in the pipe receives the result of the previous function and can modify or validate the interaction.
Pipe has two main forms:
pipe(builderFunctions)
: Returns a builder functionpipe(interaction, builderFunctions)
: Directly executes the pipe on an interaction
Import
You can import the entire package and access the function:
_10import * as fcl from "@onflow/fcl-core"_10_10fcl.pipe(fns)
Or import directly the specific function:
_10import { pipe } from "@onflow/fcl-core"_10_10pipe(fns)
Usage
_25import * as fcl from "@onflow/fcl";_25_25// Using pipe to create a reusable builder_25const myTransactionBuilder = fcl.pipe([_25 fcl.transaction`_25 transaction(amount: UFix64) {_25 prepare(account: AuthAccount) {_25 log(amount)_25 }_25 }_25 `,_25 fcl.args([fcl.arg("10.0", fcl.t.UFix64)]),_25 fcl.proposer(fcl.authz),_25 fcl.payer(fcl.authz),_25 fcl.authorizations([fcl.authz]),_25 fcl.limit(100)_25]);_25_25// Use the builder_25const interaction = await fcl.build([myTransactionBuilder]);_25_25// Pipe is used internally by build() and send()_25await fcl.send([_25 fcl.script`access(all) fun main(): Int { return 42 }`_25]); // This uses pipe internally
Parameters
fns
- Type:
(false | InteractionBuilderFn)[]
- Description: Array of builder functions to apply
Returns
_10export type InteractionBuilderFn = (_10 ix: Interaction_10) => Interaction | Promise<Interaction>
An interaction builder function when called with just functions, or a Promise<Interaction> when called with an interaction and functions