-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathbuild-script.ts
More file actions
49 lines (48 loc) · 1.59 KB
/
Copy pathbuild-script.ts
File metadata and controls
49 lines (48 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {
pipe,
put,
makeScript,
InteractionBuilderFn,
} from "../interaction/interaction"
import {template} from "@onflow/util-template"
/**
* 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](https://cadence-lang.org/docs/language), 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.
*
* @param args The arguments to pass to the template
* @returns A function that processes an interaction object
*
* @example
* import * as fcl from "@onflow/fcl";
*
* const result = await fcl.query({
* cadence: `
* access(all) fun main(a: Int, b: Int, addr: Address): Int {
* log(addr)
* return a + b
* }
* `,
* args: (arg, t) => [
* arg(7, t.Int), // a: Int
* arg(6, t.Int), // b: Int
* arg("0xba1132bc08f82fe2", t.Address), // addr: Address
* ],
* });
*
* console.log(result); // 13
*/
export function script(
...args: [
string | TemplateStringsArray | ((x?: unknown) => string),
...unknown[],
]
): InteractionBuilderFn {
return pipe([makeScript, put("ix.cadence", template(...args))])
}