cairo by example

constants

Constants store data that cannot be modified, just like immutable variables.

The key differences are:

use debug::PrintTrait;

const ONE_HOUR_IN_SECONDS: u32 = 3600;
const TICKTACKTOE_PLAYER_COUNT: u8 = 2;
const IS_COMPLETE: bool = 1;

fn main() {
  ONE_HOUR_IN_SECONDS.print();
}


Try it out!
  1. Install the toolchain:
    • For macOS and Linux, run our script:
    • curl -sL https://raw.githubusercontent.com/lambdaclass/cairo-by-example/main/build/installer.sh | bash -s 2.2.0
    • For Windows and others, please see the official guide
  2. Run the example:
    1. Copy the example into a constants.cairo file and run with:
    2. %!s(<nil>) constants.cairo

prev (loop) next (enums)