Class actor constructor variables stable

Are the constructor variables (not sure that’s the proper name, see examples below n and i) of a class actor stable ? Are these values preserved when the related canister is upgraded?

import Nat "mo:base/Nat";

actor class Bucket(n : Nat, i : Nat) {

No. You can save them to stable variables if you like though.

Note that the upgrade can specify its own parameters, and these need bare no relation to the parameters of the replaced actor.

Oh that was a good to ask! Thanks for the answer.

So if I get it, as following then.

import Nat "mo:base/Nat";

actor class Bucket(n : Nat) {
    private stable let n_stable: Nat = n;

    public query func get(): async Nat {
        return n_stable;

Yes, that should work.

1 Like