Skip to main content

script

A builder function that creates a script interaction. Scripts allow you to write arbitrary non-mutating Cadence code on the Flow blockchain and return data.

You can learn more about Cadence here, but we are now only interested in executing the script code and getting back the data.

We can execute a script using the latest state of the Flow blockchain or we can choose to execute the script at a specific time in history defined by a block height or block ID.

Block ID is SHA3-256 hash of the entire block payload, but you can get that value from the block response properties.

Block height expresses the height of the block in the chain.

Import

You can import the entire package and access the function:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.script(args)

Or import directly the specific function:


_10
import { script } from "@onflow/sdk"
_10
_10
script(args)

Usage


_17
import * as fcl from "@onflow/fcl";
_17
_17
const result = await fcl.query({
_17
cadence: `
_17
access(all) fun main(a: Int, b: Int, addr: Address): Int {
_17
log(addr)
_17
return a + b
_17
}
_17
`,
_17
args: (arg, t) => [
_17
arg(7, t.Int), // a: Int
_17
arg(6, t.Int), // b: Int
_17
arg("0xba1132bc08f82fe2", t.Address), // addr: Address
_17
],
_17
});
_17
_17
console.log(result); // 13

Parameters

args (optional)

  • Type: [string | TemplateStringsArray | ((x?: unknown) => string), ...unknown[]]
  • Description: The arguments to pass to the template

Returns

InteractionBuilderFn


_10
export type InteractionBuilderFn = (
_10
ix: Interaction
_10
) => Interaction | Promise<Interaction>


Rate this page