Variables
The State page covered defining the data your contract remembers permanently. This page introduces the three nodes you’ll use to work with that data: creating new values, reading existing ones, and updating them.
Three Variable Nodes
Each one does something different:
localVariable makes a brand new value you can use right away. Think of it like writing a number on a sticky note: it’s useful while you’re working, but it gets thrown away when you’re done.getVariable looks up a stored value so you can use it. Like checking the scoreboard: you can see the score, but you’re not changing it.setVariable changes a stored value to something new. Like updating the scoreboard after someone scores a point.
Try It Yourself
The canvas below uses the real editor. Complete each task to try out the three variable nodes.
Name a brand new variable that can hold a value.
What You Learned
localVariable makes a new temporary value you can name and usegetVariable reads a stored value without changing itsetVariable writes a new value, replacing whatever was stored before
These three nodes are the building blocks for working with data. In the next section, you’ll learn how to wire them together inside actions that run on the blockchain.
The Assign Node
The SET (Assign) node is an execution node that updates a stored value and passes it forward. It works like
- Key and Key2 fields: Access specific entries in mappings and nested mappings. For example, set
balances[userAddress]by selecting the mapping and typing or wiring the key. - Output handle: The assigned value flows out through a circle connector, so you can use it in the next step without a separate
getVariable .
Use
How hard was this?