Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 66631a0

Browse files
authored
feat: empty init() function is present by default (#221)
1 parent 6930944 commit 66631a0

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

pages/book/contracts.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ contract Example {
8080
const StateDelivered: Int = 2;
8181
const StateDisputed: Int = 3;
8282
83-
// no need to init constants
84-
init() {}
85-
8683
get fun sum(): Int {
8784
// access constants from anywhere
8885
return GlobalConst1 + self.ContractConst1 + self.StatePaid;
@@ -111,6 +108,14 @@ contract Example {
111108
}
112109
```
113110

111+
If a contract doesn't have any persistent state variables, or they all have their default value specified, it may omit the `init(){:tact}` function declaration altogether. That's because unless explicitly declared, the empty `init(){:tact}` function is present by default in all contracts.
112+
113+
The following is an example of a valid empty contract:
114+
115+
```tact
116+
contract IamEmptyAndIknowIt {}
117+
```
118+
114119
<Callout>
115120

116121
To obtain initial state of the target contract in [internal functions](#internal-functions), [receivers](#receiver-functions) or [getters](#getter-functions) use [`initOf{:tact}`](/book/expressions#initof) expression.
@@ -201,7 +206,6 @@ They can only be called from [receivers](#receiver-functions), [getters](#getter
201206
```tact
202207
contract Functions {
203208
val: Int = 0;
204-
init() {}
205209
206210
// this contract method can only be called from within this contract and access its variables
207211
fun onlyZeros() {

pages/book/exit-codes.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ Example:
175175
1. First, define an empty contract like below:
176176

177177
```tact
178-
contract Fireworks {
179-
init() {}
180-
}
178+
contract Fireworks {}
181179
```
182180

183181
2. Then, send a message to this contract. Because no suitable operation is found, you will get this exit code.
@@ -301,4 +299,4 @@ Example:
301299
// fun newAddress(chain: Int, hash: Int): Address;
302300
// creates a new address from chain and hash values.
303301
let zeroAddress: Address = newAddress(-1, 0); // masterchain zero address
304-
```
302+
```

pages/book/expressions.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ Anywhere in the function body, a global [static function](/book/functions#global
208208

209209
```tact
210210
contract ExampleContract {
211-
init() {}
212211
receive() {
213212
now(); // now() is a static function of stdlib
214213
let expiration: Int = now() + 1000; // operation and variable declaration

pages/book/maps.mdx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,6 @@ contract Example {
307307
arr: map<Int, Int>; // "array" of String values as a map
308308
arrLength: Int = 0; // length of the "array", defaults to 0
309309
310-
// Constructor (initialization) function of the contract
311-
init() {}
312-
313310
// Internal function for pushing an item to the end of the "array"
314311
fun arrPush(item: String) {
315312
if (self.arrLength >= self.MaxMapSize) {

pages/book/types.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ contract HelloWorld {
116116
counter: Int;
117117
118118
// Constructor function init(), where all the variables are initialized
119-
// Note, that an empty init function won't be needed starting with Tact 1.3.0,
120-
// see: https://github.com/tact-lang/tact/pull/167
121119
init() {
122120
self.counter = 0;
123121
}

0 commit comments

Comments
 (0)