StarknetAstro

StarknetAstro

00_Cairo Program Entry

00_Cairo Program Entry#

The version of the Cairo compiler used in this article is 2.0.0-rc0. Because Cairo is being updated rapidly, the syntax may vary slightly in different versions, and the content of the article will be updated to the stable version in the future.

Single File Cairo Program Entry#

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();
}

Run the command:

cairo-run $file_path

The main function can have a return value, as follows:

fn main() -> felt252 {
   return 10; 
}

The return value will be output in square brackets on this line:

Run completed successfully, returning [10]

Starknet Smart Contract Entry#

Start with #[starknet::contract], and add the contract name after the mod keyword.

#[starknet::contract]
mod ERC20 {
	...
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.