Scripts
A script is executable Cadence code that queries the Flow network but does not modify it. Unlike Flow transactions, they don’t need signing and they can return a value. You can think of executing scripts as a read-only operation.
Scrips are executed on Access Nodes, Archive Nodes, or Execution Nodes.
Scripts are defined by following the Cadence code and we can only execute one at a time.
_10pub fun main() {}
Scripts can return a typed value:
_10pub fun main(): Int {_10 return 1 + 2_10}
Scripts can call contract functions and query the state of a contract. To call a function on another contract, import it from its address and invoke the function:
_10import World from 0x01_10_10pub fun main(): String {_10 return World.hello()_10}
Executing Scripts
You can execute a script by using the Flow CLI:
_10flow scripts execute ./helloWorld.cdc
A user can define their own scripts or can use already defined scripts by the contract authors that can be found by using the FLIX service.
Scripts can be run against previous blocks, allowing you to query historic data from the Flow network. This is particularly useful for retrieving historical states of contracts or tracking changes over time.
Scripts are executed by being submitted to the Access Node APIs. Currently, there’s support for two APIs:
There are multiple SDKs implementing the above APIs for different languages:
Find a list of all SDKs here