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/deploying-to-network.mdx
+4-21Lines changed: 4 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -26,11 +26,11 @@ This makes it possible to calculate the future wallet smart contract address.
26
26
27
27
### Magic storage member
28
28
29
-
In previous steps, we deliberately didn't explain the purpose of `ctxID` and `ID` stored in our smart contract's state and why they remained untouched in all the smart contract functionality. Now, their purpose should start to become clearer.
29
+
In previous steps, we deliberately didn't explain the purpose of `ctx_id` and `ID` stored in our smart contract's state and why they remained untouched in all the smart contract functionality. Now, their purpose should start to become clearer.
30
30
31
31
Since we can't deploy a smart contract with the same `state_init`, the only way to provide the same initial code and **"same"** initial data is to create a separate field in it, ensuring additional uniqueness. This, in the case of a wallet, gives you the opportunity to have the same key pair for several wallet smart contracts.
32
32
33
-
### One to rule them all
33
+
{/*### One to rule them all
34
34
35
35
If you've already considered that the `ID` field is a must-have for any smart contract, there is another opportunity that could change your mind. Let's examine the previously developed `CounterInternal` smart contract's init section:
36
36
@@ -47,10 +47,10 @@ If we remove the `id` field from its initial storage, we can ensure that **only
47
47
:::info Tokens
48
48
This mechanism plays a crucial role in [Jetton Processing](/v3/guidelines/dapps/asset-processing/jettons/). Each non-native (jetton) token requires its own `Jetton Wallet` for a particular owner and, therefore, provides a calculable address for it, creating a **star scheme** with the basic wallet in the center.
49
49
:::
50
-
50
+
*/}
51
51
## Implementation
52
52
53
-
Now that our smart contracts are fully tested, we are ready to deploy them to TON. In `Blueprint SDK`, this process is the same for both `Mainnet` and `Testnet` and for any of the presented languages in the guide: `FunC`, `Tact`, or `Tolk`.
53
+
Now that our smart contracts are fully tested, we are ready to deploy them to TON. In `Blueprint SDK`, this process is the same for both `Mainnet` and `Testnet` and for any of the presented languages in the guide: `FunC` or `Tolk`.
54
54
55
55
### Step 1: update the deployment script
56
56
@@ -59,7 +59,6 @@ Deployment scripts rely on the same wrappers that you have used in testing scrip
Copy file name to clipboardExpand all lines: docs/v3/guidelines/quick-start/developing-smart-contracts/func-tolk-folder/processing-messages.mdx
+13-45Lines changed: 13 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -182,7 +182,7 @@ By combining both of these patterns, you can achieve a comprehensive description
182
182
183
183
`External messages` are your only way of toggling smart contract logic from outside the blockchain. Usually, there is no need for implementation of them in smart contracts because, in most cases, you don't want external entry points to be accessible to anyone except you. If this is all the functionality that you want from the external section, the standard way is to delegate this responsibility to a separate actor - [wallet](v3/documentation/smart-contracts/contracts-specs/wallet-contracts#basic-wallets/), which is practically the main reason they were designed for.
184
184
185
-
Developing external endpoints includes several standard [approaches](/v3/documentation/smart-contracts/message-management/external-messages/) and [security measures](/v3/guidelines/smart-contracts/security/overview/) that might be overwhelming at this point. Therefore, in this guide, we will implement incrementing the previously added `ctxCounterExt` number and add a send message to our `Tact` contract.
185
+
Developing external endpoints includes several standard [approaches](/v3/documentation/smart-contracts/message-management/external-messages/) and [security measures](/v3/guidelines/smart-contracts/security/overview/) that might be overwhelming at this point. Therefore, in this guide, we will implement incrementing the previously added `ctx_counter_ext` number.
186
186
187
187
:::danger
188
188
This implementation is **unsafe** and may lead to losing your contract funds. Don't deploy it to `Mainnet`, especially with a high smart contract balance.
@@ -259,7 +259,7 @@ fun onExternalMessage(inMsg: slice) {
259
259
</TabItem>
260
260
</Tabs>
261
261
262
-
This function, upon receiving an external message, will increment our `ctxCounterExt` and also send an internal message to the specified address with the `increase` operation, which we will use to increment the counter on our `CounterInternal` smart contract.
262
+
This function, upon receiving an external message, will increment our `ctx_counter_ext` and also send an internal message to the specified address with the `increase` operation.
263
263
264
264
Verify that the smart contract code is correct by running:
265
265
@@ -308,13 +308,12 @@ async sendExternalIncrease(
308
308
309
309
### Step 3: update test
310
310
311
-
Update the test to ensure that the `HelloWorld` contract received the external message, sent an internal message to the `CounterInternal` contract, and both updated their counters:
311
+
Update the test to ensure that the `HelloWorld` contract received the external message, and updated its counters:
This test describes the common transaction flow of any `multi-contract` system:
412
-
1. Send an external message to toggle the smart contract logic from outside the blockchain.
380
+
{/*This test describes the common transaction flow of any `multi-contract` system:
381
+
1. Send an external message to toggle the smart contract logic outside the blockchain.
413
382
2. Trigger one or more internal messages to be sent to other contracts.
414
383
3. Upon receiving an internal message, change the contract state and repeat **step 2** if required.
415
384
416
385
Since the resulting sequence of transactions might be overwhelming for understanding, it's a good practice to create a `sequence diagram` describing your system. Here is an example of our case:
Copy file name to clipboardExpand all lines: docs/v3/guidelines/quick-start/developing-smart-contracts/func-tolk-folder/storage-and-get-methods.mdx
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -37,9 +37,9 @@ Let's examine the [Cell](/v3/concepts/dive-into-ton/ton-blockchain/cells-as-data
37
37
38
38
TON Blockchain uses a data structure called **Cell** as the fundamental unit for storing data. Cells are the building blocks of smart contract data and have the following characteristics:
39
39
40
-
- A Cell can store up to 1023 bits (approximately 128 bytes) of data
41
-
- A Cell can reference up to 4 other Cells (children)
42
-
- A Cell is immutable once created
40
+
- A Cell can store up to 1023 bits (approximately 128 bytes) of data.
41
+
- A Cell can reference up to 4 other Cells (children).
42
+
- A Cell is immutable once created.
43
43
44
44
You can think of a Cell as the following structure:
45
45
@@ -118,11 +118,11 @@ fun saveData() {
118
118
Let's modify our example slightly by exploring another common storage management approach in smart contract development:
119
119
120
120
Rather than initializing global variables, we'll:
121
-
1. Pass storage members as parameters via `save_data(members...)`
122
-
2. Retrieve them using `(members...) = get_data()`
123
-
3. Move the global variables `ctx_id` and `ctx_counter` into method bodies
121
+
1. Pass storage members as parameters via `save_data(members...)`.
122
+
2. Retrieve them using `(members...) = get_data()`.
123
+
3. Move the global variables `ctx_id` and `ctx_counter` into the method bodies.
124
124
125
-
Also let's add an additional **256-bit integer** to our storage. The modified implementation should appear as follows:
125
+
Also let's add an additional **256-bit integer** to our storage as `ctx_counter_ext` global variable. The modified implementation should appear as follows:
@@ -52,7 +53,7 @@ This will run an interactive script to create the project template. You can ente
52
53
53
54
1.**Project name**: `Example`
54
55
2.**First contract name**: `HelloWorld`
55
-
3.**Project template**: A**simple counter contract** in `FunC`or `Tact`
56
+
3.**Project template**: a**simple counter contract** in `FunC`, `Tolk`or `Tact`
56
57
57
58
Finally, change your current directory to the generated project template folder and install all required dependencies:
58
59
@@ -61,10 +62,35 @@ cd ./Example
61
62
npm install
62
63
```
63
64
64
-
### Step 4 (Optional): IDE and editor support
65
+
### Step 4 (optional): IDE and editor support
65
66
66
67
The TON community has developed plugins that provide syntax support for several IDEs and code editors. You can find them here: [Plugin List](https://docs.ton.org/v3/documentation/smart-contracts/getting-started/ide-plugins/).
67
68
68
69
Also, consider installing plugins that support **JavaScript/TypeScript** tools for your preferred IDE or code editor, specifically `Jest`, for debugging smart contract tests.
69
70
71
+
72
+
73
+
## Choose the programming language
74
+
75
+
Now that your environment is set up choose a programming language to get started:
76
+
77
+
-**FunC or Tolk**: estimated time to learn is 40 min for each.
> **Summary:** In the previous steps, we installed and configured all the tools required for TON smart contract development and created our first project template.
8
+
9
+
Before we proceed to actual smart contract development, let's briefly describe the project structure and explain how to use the **`Blueprint SDK`**.
10
+
11
+
## Project structure
12
+
13
+
:::warning
14
+
If you didn't choose the proposed names in the previous steps, source code file names and some of the in-code entities may differ.
├── scripts/ # Deployment and on-chain interaction scripts
41
+
│ ├── deployHelloWorld.ts # Script to deploy the contract
42
+
│ └── incrementHelloWorld.ts # Script to interact with the contract
43
+
├── tests/ # Test fo der for local contract testing
44
+
│ └── HelloWorld.spec.ts # Test specifications for the contract
45
+
└── wrappers/ # TypeScript wrappers for contract interaction
46
+
├── HelloWorld.ts # Wrapper class for smart contract
47
+
└── HelloWorld.compile.ts # Script for contract compilation
48
+
```
49
+
</TabItem>
50
+
</Tabs>
51
+
52
+
### `/contracts`
53
+
54
+
This folder contains your smart contract source code written in one of the available programming languages used for TON Blockchain smart contract development.
55
+
56
+
### `/wrappers`
57
+
58
+
To interact with your smart contract off-chain, you need to serialize and deserialize messages sent to it. `Wrapper` classes are developed to mirror your smart contract implementation, making its functionality simple to use.
59
+
60
+
### `/tests`
61
+
62
+
This directory contains test files for your smart contracts. Testing contracts directly on the TON network is not the best option because deployment requires some amount of time and may lead to losing funds. This testing playground allows you to execute multiple smart contracts and even send messages between them in your **"local network"**. Tests are crucial for ensuring your smart contracts behave as expected before deployment to the network.
63
+
64
+
### `/scripts`
65
+
66
+
The `scripts` directory contains `TypeScript` files that help you deploy and interact with your smart contracts on-chain using previously implemented wrappers.
67
+
68
+
## Development flow
69
+
70
+
Almost any smart contract project development consists of five simple steps:
71
+
72
+
1. Edit the smart contract code in the `/contracts` folder and build it by running the build script:
73
+
74
+
```bash
75
+
npx blueprint build
76
+
```
77
+
78
+
2. Update the smart contract wrapper in the `/wrappers` folder to correspond to changes in the contract.
79
+
80
+
3. Update tests in the `/tests` folder to ensure the correctness of the new functionality and run the test script:
81
+
82
+
```bash
83
+
npx blueprint test
84
+
```
85
+
86
+
4. Repeat steps 1-3 until you achieve the desired result.
87
+
88
+
5. Update the deployment script in the `/scripts` folder and run it using this command:
89
+
90
+
```bash
91
+
npx blueprint run
92
+
```
93
+
94
+
:::tip
95
+
All examples in this guide follow the sequence of these **1-3 steps** with corresponding code samples. **Step 5**, the deployment process, is covered in the last section of the guide: [Deploying to network](/v3/guidelines/quick-start/developing-smart-contracts/deploying-to-network/).
96
+
:::
97
+
98
+
Also, you can always generate the same structure for another smart contract if, for example, you want to create multiple contracts interacting with each other by using the following command:
99
+
100
+
```bash
101
+
npx blueprint create PascalCase # Don't forget to name the contract in PascalCase
0 commit comments