You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/v3/guidelines/quick-start/developing-smart-contracts/func-tolk-folder/storage-and-get-methods.mdx
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ import Button from '@site/src/components/button'
11
11
If you're stuck on any of the examples, you can find the original template project with all modifications made during this guide [here](https://github.com/ton-community/onboarding-sandbox/tree/main/quick-start/smart-contracts/Example/contracts).
12
12
:::
13
13
14
-
Almost all smart contracts need to store their `data` between transactions. This guide explains standard ways to manage `storage` for smart contracts and how to use `get methods` to access it from outside the blockchain.
14
+
Almost all smart contracts need to store their `data` between transactions. This guide explains standard ways to manage `storage` for smart contracts and how to use `get methods` to access it outside the blockchain.
@@ -5,13 +5,17 @@ import Button from '@site/src/components/button'
5
5
6
6
# Storage and get methods
7
7
8
-
> **Summary:** In the previous steps, we learned how to use the `Blueprint` and its project structure.
8
+
> **Summary:** In the previous steps, we learned how to use the `Blueprint SDK` and its project structure.
9
9
10
10
:::info
11
11
For more details, refer to the [Tact documentation](https://docs.tact-lang.org/#start/) and [Tact By Example](https://tact-by-example.org/00-hello-world/).
12
12
:::
13
13
14
-
Let's create and modify our smart contract following standard steps described in the previous [Blueprint overview](/v3/guidelines/quick-start/developing-smart-contracts/tact-folder/tact-blueprint-sdk-overview/) section.
14
+
15
+
Smart contracts often need to store data, like counters or ownership information, and provide a way to read or update it through messages. In this section, you’ll learn how to define and initialize contract storage, receive and handle incoming messages, restrict access using traits, and create getter functions to read contract states outside the blockchain.
16
+
17
+
Let's create and modify our smart contract following the standard steps described in the previous [Blueprint overview](/v3/guidelines/quick-start/developing-smart-contracts/tact-folder/tact-blueprint-sdk-overview/) section.
18
+
15
19
16
20
## Step 1: edit smart contract code
17
21
@@ -78,26 +82,16 @@ A contract may store its state variables as follows. They may be accessed with [
78
82
id: Int as uint32;
79
83
counter: Int as uint32;
80
84
```
81
-
82
-
To ensure that only the contract owner can interact with specific functions, add an `owner` field:
83
-
84
-
```tact title="/contracts/hello_world.tact"
85
-
id: Int as uint32;
86
-
counter: Int as uint32;
87
-
owner: Address;
88
-
```
89
-
90
85
These fields are serialized similarly to structures and stored in the contract's data register.
91
86
92
87
#### Initializing the contract
93
88
94
-
If you compile the contract at this stage, you will encounter the error: `Field "owner" is not set`. This is because the contract needs to initialize its fields upon deployment. Define an [`init()`](https://docs.tact-lang.org/book/contracts/#init-function/) function to do this:
89
+
Define an [`init()`](https://docs.tact-lang.org/book/contracts/#init-function/) function to do this:
95
90
96
91
```tact title="/contracts/hello_world.tact"
97
92
init(id: Int, owner: Address) {
98
93
self.id = id;
99
94
self.counter = 0;
100
-
self.owner = owner;
101
95
}
102
96
```
103
97
@@ -248,174 +242,181 @@ This code exports everything inside the `tact_HelloWorld.ts` file in the build f
248
242
249
243
## Step 3: updating tests
250
244
251
-
Now let's ensure that our smart contract code fails when we try to send `add` message from non-owner:
252
-
- Create `HelloWorld` with some owner.
253
-
- Create another smart contract that will have different address - `nonOwner`.
254
-
- Try to send an internal message to `HelloWorld` and enusre that it fails with expected `exitCode` and counter field remains the same.
0 commit comments