Skip to main content

run

Runs a set of functions on an interaction

This is a utility function for testing that builds and resolves an interaction with the provided builder functions. It automatically adds a reference block and then resolves the interaction for testing purposes.

Import

You can import the entire package and access the function:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.run(fns)

Or import directly the specific function:


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

Usage


_28
import { run } from "@onflow/sdk"
_28
import * as fcl from "@onflow/fcl";
_28
_28
// Test a simple script interaction
_28
const result = await run([
_28
fcl.script`
_28
access(all) fun main(): Int {
_28
return 42
_28
}
_28
`
_28
]);
_28
_28
console.log(result.cadence); // The Cadence script
_28
console.log(result.tag); // "SCRIPT"
_28
_28
// Test a transaction with arguments
_28
const txResult = await run([
_28
fcl.transaction`
_28
transaction(amount: UFix64) {
_28
prepare(account: AuthAccount) {
_28
log(amount)
_28
}
_28
}
_28
`,
_28
fcl.args([fcl.arg("10.0", fcl.t.UFix64)])
_28
]);
_28
_28
console.log(txResult.message.arguments); // The resolved arguments

Parameters

fns (optional)

  • Type: ((ix: Interaction) => Interaction | Promise<Interaction>)[]
  • Description: An array of functions to run on the interaction

Returns

Promise<Interaction>


Rate this page