Calling Other Functions
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.
Defining a contract
A contract may be declared and given a name using the contract
keyword (see snippet below). By convention, contracts are named in PascalCase
.
contract MyContract {
// Imports
// Storage
// Functions
}
There is no main()
(GitHub link) function within a Noir contract
scope. More than one function can be an entrypoint.
Add as a dependency in Nargo.toml
Import the contract that you want to call into your Nargo.toml
under dependencies
like this:
token = { git="https://github.com/AztecProtocol/aztec-packages/", tag="aztec-packages-v0.64.0", directory="noir-projects/noir-contracts/contracts/token_contract" }
Import into your contract
At the top of your contract, import the contract you want to call like this:
use token::Token;