Contract Structure
A contract is a collection of persistent state variables and functions which may manipulate these variables. Functions and state variables within a contract's scope are said to belong to that contract.
A contract can only access and modify its own state. If a contract wishes to access or modify another contract's state, it must make a call to an external function of the other contract. For anything to happen on the Aztec network, an external function of a contract needs to be called.
Contract
A contract is declared using the #[aztec] attribute and the contract keyword. By convention, contracts are named in PascalCase.
use dep::aztec::macros::aztec;
#[aztec]
pub contract Counter {
Source code: docs/examples/contracts/counter_contract/src/main.nr#L1-L6
There is no main() function within a Noir contract scope. More than one function can be an entrypoint.
Directory structure
Here's a common layout for a basic Aztec.nr Contract project:
─── my_aztec_contract_project
├── src
│ └── main.nr <-- your contract
└── Nargo.toml <-- package and dependency management
See the vanilla Noir docs for more info on packages.
Next steps
- Define functions - Learn about private, public, and utility functions
- Define storage - Work with persistent state variables
- Compile your contract - Build your contract artifact