00_Cairo Program Entry#
The version of the Cairo compiler used in this article is 2.0.0-rc0. Since Cairo is being updated rapidly, there may be slight differences in syntax between different versions. The article will be updated to a stable version in the future.
Entry Point for Single-File Cairo Programs#
Similar to most programming languages, the entry point for a single-file Cairo program is the main function.
use debug::PrintTrait;
const ONE_HOUR_IN_SECONDS: felt252 = 3600;
fn main(){
ONE_HOUR_IN_SECONDS.print();
}
To run the program, use the following command:
cairo-run $file_path
The main function can have a return value, as shown below:
fn main() -> felt252 {
return 10;
}
The return value will be output within square brackets on this line:
Run completed successfully, returning [10]
Entry Point for Starknet Smart Contracts#
Start with #[starknet::contract]
, and add the contract name after the mod keyword.
#[starknet::contract]
mod ERC20 {
...
}