-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docs): Update other constructor refs in docs to use initializer (#…
…5227) Please read [contributing guidelines](CONTRIBUTING.md) and remove this line. --------- Co-authored-by: Santiago Palladino <[email protected]>
- Loading branch information
1 parent
79c6e99
commit f68ff28
Showing
5 changed files
with
41 additions
and
50 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
docs/docs/developers/contracts/writing_contracts/functions/initializers.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: How to write an initializer function | ||
--- | ||
|
||
This page explains how to write an initializer function. | ||
|
||
To learn more about initializers, read [this](./main.md#initializer-functions). | ||
|
||
Initializers are regular functions that set an "initialized" flag (a nullifier) for the contract. A contract can only be initialized once, and contract functions can only be called after the contract has been initialized, much like a constructor. However, if a contract defines no initializers, it can be called at any time. Additionally, you can define as many initializer functions in a contract as you want, both private and public. | ||
|
||
## Annotate with `#[aztec(private)]` and `#[aztec(initializer)]` | ||
|
||
|
||
Define your initiaizer like so: | ||
|
||
```rust | ||
#[aztec(private)] | ||
#[aztec(initializer)] | ||
fn constructor(){ | ||
// function logic here | ||
} | ||
``` | ||
|
||
## Initializer with logic | ||
|
||
Initializers are commonly used to set an admin, such as this example: | ||
|
||
#include_code constructor /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust | ||
|
||
Here, the initializer is calling a public function. It can also call a private function. Learn more about calling functions from functions [here](../functions/call_functions.md). | ||
|
||
To see constructors in action, check out the [Aztec.nr getting started guide](../../../getting_started/aztecnr-getting-started.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
docs/docs/developers/contracts/writing_contracts/functions/write_constructor.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters