Global State Variables in Daml

How to initialize global Variable in DAML?
Do Global Variables exist in DAML?

There are a few points to this question:

First, Daml contracts are immutable and there are no builtin mutable variables. You can however use contract keys to model mutable state.

Second, Daml contracts are always scoped to a set of parties. In the case of contract keys those are the maintainers of the contract key.

So there is nothing that is quite equivalent to a global variable in general purpose programming languages but for a given set of parties, you can model “global” (scoped to those parties) state controlled by those parties as a contract with a contract key which has those parties as maintainers.

If you have some example code of what you are trying to do, we might be able to provide some more concrete suggestions.

1 Like