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.

Task 1 of 3 Create a Variable

Name a brand new variable that can hold a value.

1 Name it
2 Done!
Type score in the Name field on the node.
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

What You Learned

  • localVariable makes a new temporary value you can name and use
  • getVariable reads a stored value without changing it
  • setVariable 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 setVariable but with two extra capabilities:

  • 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 setVariable for simple updates. Use the Assign node when you need mapping key access or want to chain the result into another node.