Skip to content
LogoLogo

Counter

A first stateful contract. uint is an unsigned 256-bit integer and 1 here is a uint.

counter.lithe
storage is record {
  count : uint;
}
 
external view function get() : uint is
  storage.count
 
external function inc() is {
  storage.count := storage.count + 1;
}
 
(* `uint` never goes negative. Decrementing zero reverts with Panic(0x11). *)
external function dec() is {
  storage.count := storage.count - 1;
}

Try it:

lithe compile counter.lithe     # creation bytecode
lithe footprint counter.lithe   # what each entrypoint reads and writes
inc   writes: count            during defers: callable
dec   writes: count            during defers: callable
get   reads: count             during defers: callable