The backend functions are located in the src/persistent_storage/main.mo Motoko file. The backend stores the counter value, and has functions to get, increment and reset the counter value. Furthermore the backend insures the counter value persists upgrades of the dapp.
The current counter value is stored as a number in the actor.
actor {
stable var counter : Nat = 0;
}The increment() function increments the counter variable.
public func increment() : async Nat {
counter += 1;
return counter;
};The function is returning the incremented counter variable.
The get() function returns the current counter value.
public query func get() : async Nat {
return counter;
};The reset() function resets the counter value to 0 and returns the value.
public func reset() : async Nat {
counter := 0;
return counter;
};The Candid interface is automatically created, and it has a convenient UI, which provides an easy, user-friendly way to test the backend.