diff --git a/pages/book/contracts.mdx b/pages/book/contracts.mdx index b4395d08..ba2ea42f 100644 --- a/pages/book/contracts.mdx +++ b/pages/book/contracts.mdx @@ -80,9 +80,6 @@ contract Example { const StateDelivered: Int = 2; const StateDisputed: Int = 3; - // no need to init constants - init() {} - get fun sum(): Int { // access constants from anywhere return GlobalConst1 + self.ContractConst1 + self.StatePaid; @@ -111,6 +108,14 @@ contract Example { } ``` +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. + +The following is an example of a valid empty contract: + +```tact +contract IamEmptyAndIknowIt {} +``` + 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 ```tact contract Functions { val: Int = 0; - init() {} // this contract method can only be called from within this contract and access its variables fun onlyZeros() { diff --git a/pages/book/exit-codes.mdx b/pages/book/exit-codes.mdx index 32c47d60..68de7e2c 100644 --- a/pages/book/exit-codes.mdx +++ b/pages/book/exit-codes.mdx @@ -175,9 +175,7 @@ Example: 1. First, define an empty contract like below: ```tact -contract Fireworks { - init() {} -} +contract Fireworks {} ``` 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: // fun newAddress(chain: Int, hash: Int): Address; // creates a new address from chain and hash values. let zeroAddress: Address = newAddress(-1, 0); // masterchain zero address -``` \ No newline at end of file +``` diff --git a/pages/book/expressions.mdx b/pages/book/expressions.mdx index e6b7a045..3d85a3cf 100644 --- a/pages/book/expressions.mdx +++ b/pages/book/expressions.mdx @@ -208,7 +208,6 @@ Anywhere in the function body, a global [static function](/book/functions#global ```tact contract ExampleContract { - init() {} receive() { now(); // now() is a static function of stdlib let expiration: Int = now() + 1000; // operation and variable declaration diff --git a/pages/book/maps.mdx b/pages/book/maps.mdx index 7c588fe8..d4356732 100644 --- a/pages/book/maps.mdx +++ b/pages/book/maps.mdx @@ -289,9 +289,6 @@ contract Example { arr: map; // "array" of String values as a map arrLength: Int = 0; // length of the "array", defaults to 0 - // Constructor (initialization) function of the contract - init() {} - // Internal function for pushing an item to the end of the "array" fun arrPush(item: String) { if (self.arrLength >= self.MaxMapSize) { diff --git a/pages/book/types.mdx b/pages/book/types.mdx index ae940ed1..6ac92abb 100644 --- a/pages/book/types.mdx +++ b/pages/book/types.mdx @@ -116,8 +116,6 @@ contract HelloWorld { counter: Int; // Constructor function init(), where all the variables are initialized - // Note, that an empty init function won't be needed starting with Tact 1.3.0, - // see: https://github.com/tact-lang/tact/pull/167 init() { self.counter = 0; }