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:
_10import * as sdk from "@onflow/sdk"_10_10sdk.script(args)
Or import directly the specific function:
_10import { script } from "@onflow/sdk"_10_10script(args)
Usage
_17import * as fcl from "@onflow/fcl";_17_17const 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_17console.log(result); // 13
Parameters
args
(optional)
- Type:
[string | TemplateStringsArray | ((x?: unknown) => string), ...unknown[]]
- Description: The arguments to pass to the template
Returns
InteractionBuilderFn
_10export type InteractionBuilderFn = (_10 ix: Interaction_10) => Interaction | Promise<Interaction>