logo
Writing your Main Function

Overview: Welcome to writing your first Cairo program. We will not be diving in to writing Starknet contracts until later modules, but will rather focus on Cairo fundamentals for now.

The main function is the starting point of every Cairo program. Therefore, our first lesson is starting with the main() function. Let's do that now.



Some things to know about functions:

  • The keyword func is used to define a function
  • Every function signature must end with a {
  • Every function must have a return statement
  • Every function must end with a }
  • Like Solidity, statements and expressions end in a ; (semicolon)



Here is a sample of a function called triality with no parameters nor return values.

func triality() {

return();

}



Your turn:

Modify the code to write a function named main that has no parameters nor return values.

References:

For official docs on main function: $ https://www.cairo-lang.org/docs/hello_cairo/intro.html$ 


Back

1 / 4


Twitter