Skip to content

Commit 7cec4e5

Browse files
committed
Cover __init__ function for contracts
Fixes argotorg#792
1 parent 5eb4e2d commit 7cec4e5

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

docs/src/spec/items/contracts.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ contract GuestBook {
4646
}
4747
```
4848

49+
## The `__init__` function
50+
51+
The `__init__` function is a special contract function that can only be called at *contract deployment time*. It is mostly used to set initial values to storage variables upon deployment.
52+
53+
```fe
54+
pub contract Example {
55+
56+
admin: address
57+
58+
pub fn __init__(mut self, admin: address) {
59+
self.admin = admin
60+
}
61+
}
62+
```
63+
64+
It is **not possible** to call `__init__` at runtime.
65+
4966
[NEWLINE]: ../lexical_structure/tokens.md#newline
5067
[IDENTIFIER]: ../lexical_structure/identifiers.md
5168
[_Visibility_]: ./visibility_and_privacy.md

0 commit comments

Comments
 (0)