Skip to main content

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:

  1. pipe(builderFunctions): Returns a builder function
  2. pipe(interaction, builderFunctions): Directly executes the pipe on an interaction

Import

You can import the entire package and access the function:


_10
import * as fcl from "@onflow/fcl-react-native"
_10
_10
fcl.pipe(fns)

Or import directly the specific function:


_10
import { pipe } from "@onflow/fcl-react-native"
_10
_10
pipe(fns)

Usage


_25
import * as fcl from "@onflow/fcl";
_25
_25
// Using pipe to create a reusable builder
_25
const 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
_25
const interaction = await fcl.build([myTransactionBuilder]);
_25
_25
// Pipe is used internally by build() and send()
_25
await 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


_10
export 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


Rate this page