Skip to content

Commit 1d1054a

Browse files
authored
Onboarding guide: user flow new (#1147)
* order * func-tolk flow * tact flow * navigation * minor * minor * minor * test * test * getting started * read-write-to-the-network-sections * buttons * minor * minor * check * check
1 parent ddecb20 commit 1d1054a

12 files changed

+534
-174
lines changed

docs/v3/guidelines/quick-start/blockchain-interaction/reading-from-network.mdx

+26-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Feedback from "@site/src/components/Feedback";
22
import ThemedImage from "@theme/ThemedImage";
3+
import Button from '@site/src/components/button'
34

45
# Reading from network
56

67
## Introduction
78

8-
99
This guide will walk you through reading data from TON Blockchain. You'll learn how to:
1010
- Fetch account information
1111
- Call `get methods`
@@ -26,22 +26,22 @@ Versions of `node` and `npm` should be at least `v20` and `v10` correspondingly.
2626

2727
## Project setup
2828

29-
Let's set up our project structure:
30-
31-
1. Create a new directory for your project
32-
2. Initialize a Node.js project
33-
3. Install the required dependencies
29+
Lets set up your project structure:
30+
1. Create a new directory for your project and navigate into it.
31+
2. Initialize a Node.js project.
32+
3. Install the required dependencies.
33+
4. Initialize TypeScript configuration.
3434

3535
Run these commands in your terminal:
3636

3737
```bash
38-
mkdir reading-from-ton && cd reading-from-ton # create new directory and cd to it
39-
npm init -y # initialize Node.js project
40-
npm install typescript ts-node @ton/ton @ton/core @ton/crypto #install required dependecies
41-
npx tsc --init # initialize typesctipt
38+
mkdir reading-from-ton && cd reading-from-ton
39+
npm init -y
40+
npm install typescript ts-node @ton/ton @ton/core @ton/crypto
41+
npx tsc --init
4242
```
4343

44-
To run scripts, use the following command:
44+
To run a TypeScript script saved as `script.ts` in your current directory, run:
4545

4646
```bash
4747
npx ts-node script.ts
@@ -327,4 +327,19 @@ Sender: EQBui16XCF61MSWauIDpVFbKAOJmjLHRxXvXeqiN9dYaIgjq
327327
A more complex example of traversing transactions graph may be found [here](https://docs.ton.org/v3/guidelines/dapps/asset-processing/payments-processing/#retrieve-incomingoutgoing-transactions).
328328
:::
329329

330+
## Next step
331+
332+
Now that you’ve learned how to read data from TON Blockchain, it’s time to explore how to **write data to the network**.
333+
334+
Click the button below to continue:
335+
336+
<Button href="/v3/guidelines/quick-start/blockchain-interaction/writing-to-network" colorType={'primary'} sizeType={'sm'}>
337+
338+
Writing to the network
339+
340+
</Button>
341+
342+
330343
<Feedback />
344+
345+

docs/v3/guidelines/quick-start/blockchain-interaction/writing-to-network.mdx

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Feedback from "@site/src/components/Feedback";
22
import ThemedImage from "@theme/ThemedImage";
3+
import Button from '@site/src/components/button'
34

45
# Writing to the network
56

@@ -209,4 +210,16 @@ npx ts-node 2-send-nft.ts
209210

210211
Navigate to [Tonviewer](https://testnet.tonviewer.com/) and paste your address into the search bar. You should see an NFT transfer with the *'Hello from NFT!'* comment.
211212

213+
## Next step
214+
215+
Now that you’ve learned how to write data to TON Blockchain, it’s time to move on to the next stage—**developing your smart contracts**. You’ll first need to **set up your development environment** with the necessary tools and libraries to do that.
216+
217+
Click the button below to get started:
218+
219+
<Button href="/v3/guidelines/quick-start/developing-smart-contracts/setup-environment" colorType={'primary'} sizeType={'sm'}>
220+
221+
Setup development environment
222+
223+
</Button>
224+
212225
<Feedback />

docs/v3/guidelines/quick-start/developing-smart-contracts/blueprint-sdk-overview.mdx renamed to docs/v3/guidelines/quick-start/developing-smart-contracts/func-tolk-folder/blueprint-sdk-overview.mdx

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Feedback from "@site/src/components/Feedback";
22
import Tabs from '@theme/Tabs';
33
import TabItem from '@theme/TabItem';
4+
import Button from '@site/src/components/button'
45

56
# Blueprint SDK overview
67

@@ -53,17 +54,18 @@ Example/
5354

5455
This folder contains your smart contract source code written in one of the available programming languages used for TON Blockchain smart contract development.
5556

56-
### `/wrappers`
57+
### `/scripts`
5758

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+
The `scripts` directory contains `TypeScript` files that help you deploy and interact with your smart contracts on-chain using previously implemented wrappers.
5960

6061
### `/tests`
6162

6263
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.
6364

64-
### `/scripts`
65+
### `/wrappers`
66+
67+
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.
6568

66-
The `scripts` directory contains `TypeScript` files that help you deploy and interact with your smart contracts on-chain using previously implemented wrappers.
6769

6870
## Development flow
6971

@@ -101,4 +103,14 @@ Also, you can always generate the same structure for another smart contract if,
101103
npx blueprint create PascalCase # Don't forget to name the contract in PascalCase
102104
```
103105

106+
## Next step
107+
108+
Now you’re all set — it's time to start writing smart contracts. We’ll begin with the basics: **storage** and **get methods**.
109+
110+
<Button href="/v3/guidelines/quick-start/developing-smart-contracts/func-tolk-folder/storage-and-get-methods" colorType={'primary'} sizeType={'sm'}>
111+
112+
Storage & get methods
113+
114+
</Button>
115+
104116
<Feedback />

docs/v3/guidelines/quick-start/developing-smart-contracts/deploying-to-network.mdx renamed to docs/v3/guidelines/quick-start/developing-smart-contracts/func-tolk-folder/deploying-to-network.mdx

+6-22
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ This makes it possible to calculate the future wallet smart contract address.
2626

2727
### Magic storage member
2828

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.
3030

3131
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.
3232

33-
### One to rule them all
33+
{/*### One to rule them all
3434
3535
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:
3636
@@ -47,19 +47,19 @@ If we remove the `id` field from its initial storage, we can ensure that **only
4747
:::info Tokens
4848
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.
4949
:::
50-
50+
*/}
5151
## Implementation
5252

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`.
5454

5555
### Step 1: update the deployment script
5656

5757
Deployment scripts rely on the same wrappers that you have used in testing scripts. We will use one common script to deploy both of the previously deployed smart contracts. Update `deployHelloWorld.ts` with this code:
5858

5959
```typescript title="/scripts/deployHelloWorld.ts"
60+
// @version TypeScript 5.8.3
6061
import { toNano } from '@ton/core';
6162
import { HelloWorld } from '../wrappers/HelloWorld';
62-
import { CounterInternal } from '../wrappers/CounterInternal';
6363
import { compile, NetworkProvider } from '@ton/blueprint';
6464

6565
export async function run(provider: NetworkProvider) {
@@ -78,23 +78,7 @@ export async function run(provider: NetworkProvider) {
7878

7979
await provider.waitForDeploy(helloWorld.address);
8080

81-
const counterInternal = provider.open(
82-
await CounterInternal.fromInit(
83-
BigInt(Math.floor(Math.random() * 10000)),
84-
helloWorld.address
85-
)
86-
);
87-
88-
await counterInternal.send(
89-
provider.sender(),
90-
{ value: toNano('0.05') },
91-
null
92-
);
93-
94-
await provider.waitForDeploy(counterInternal.address);
95-
9681
console.log('ID', await helloWorld.getID());
97-
console.log('ID', (await counterInternal.getId()).toString());
9882
}
9983
```
10084

@@ -103,7 +87,7 @@ export async function run(provider: NetworkProvider) {
10387
You can run the script by entering the following command:
10488

10589
```bash
106-
npx blueprint run # deployHelloWorld # optionally directly pass script
90+
npx blueprint run deployHelloWorld
10791
```
10892

10993
### Step 3: choose network

docs/v3/guidelines/quick-start/developing-smart-contracts/processing-messages.mdx renamed to docs/v3/guidelines/quick-start/developing-smart-contracts/func-tolk-folder/processing-messages.mdx

+25-45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Tabs from '@theme/Tabs';
22
import TabItem from '@theme/TabItem';
33
import Feedback from "@site/src/components/Feedback";
4+
import Button from '@site/src/components/button'
45

56
# Processing messages
67

@@ -182,7 +183,7 @@ By combining both of these patterns, you can achieve a comprehensive description
182183

183184
`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.
184185

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.
186+
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.
186187

187188
:::danger
188189
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 +260,7 @@ fun onExternalMessage(inMsg: slice) {
259260
</TabItem>
260261
</Tabs>
261262

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.
263+
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.
263264

264265
Verify that the smart contract code is correct by running:
265266

@@ -308,13 +309,13 @@ async sendExternalIncrease(
308309

309310
### Step 3: update test
310311

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:
312+
Update the test to ensure that the `HelloWorld` contract received the external message, and updated its counters:
312313

313314
```typescript title="/tests/HelloWorld.spec.ts"
315+
//@version TypeScript 5.8.3
314316
import { Blockchain, SandboxContract, TreasuryContract } from '@ton/sandbox';
315317
import { Cell, toNano} from '@ton/core';
316318
import { HelloWorld } from '../wrappers/HelloWorld';
317-
import { CounterInternal } from '../wrappers/CounterInternal';
318319
import '@ton/test-utils';
319320
import { compile } from '@ton/blueprint';
320321

@@ -328,7 +329,6 @@ describe('HelloWorld', () => {
328329
let blockchain: Blockchain;
329330
let deployer: SandboxContract<TreasuryContract>;
330331
let helloWorld: SandboxContract<HelloWorld>;
331-
let counterInternal: SandboxContract<CounterInternal>;
332332

333333
beforeEach(async () => {
334334
blockchain = await Blockchain.create();
@@ -354,34 +354,16 @@ describe('HelloWorld', () => {
354354
deploy: true,
355355
success: true,
356356
});
357-
358-
counterInternal = blockchain.openContract(
359-
await CounterInternal.fromInit(0n, helloWorld.address)
360-
);
361-
362-
const deployResultCounter = await counterInternal.send(
363-
deployer.getSender(),
364-
{ value: toNano('1.00') },
365-
null
366-
);
367-
368-
expect(deployResultCounter.transactions).toHaveTransaction({
369-
from: deployer.address,
370-
to: counterInternal.address,
371-
deploy: true,
372-
success: true
373-
});
374357
});
375358

376-
it('should send an external message and update counter', async () => {
377-
const counterInternalValueBefore = await counterInternal.getCounter();
359+
it('should receive external message and update counter', async () => {
378360
const [__, counterExtBefore] = await helloWorld.getCounters()
379361
const increase = 5;
380362

381363
const result = await helloWorld.sendExternalIncrease({
382364
increaseBy: increase,
383365
value: toNano(0.05),
384-
addr: counterInternal.address,
366+
addr: deployer.address, // Using deployer address
385367
queryID: 0
386368
});
387369

@@ -391,33 +373,22 @@ describe('HelloWorld', () => {
391373
success: true,
392374
});
393375

394-
expect(result.transactions).toHaveTransaction({
395-
from: helloWorld.address,
396-
to: counterInternal.address,
397-
success: true,
398-
});
399-
400-
const counterInternalValueAfter = await counterInternal.getCounter();
401-
402-
expect(counterInternalValueAfter).toBeGreaterThan(counterInternalValueBefore);
403376
const [_, counterExt] = await helloWorld.getCounters()
404377
expect(counterExtBefore + BigInt(increase)).toBe(counterExt);
405378
});
406-
407-
// ... previous tests
408379
});
409380
```
410381

411-
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.
382+
{/*This test describes the common transaction flow of any `multi-contract` system:
383+
1. Send an external message to toggle the smart contract logic outside the blockchain.
413384
2. Trigger one or more internal messages to be sent to other contracts.
414385
3. Upon receiving an internal message, change the contract state and repeat **step 2** if required.
415386
416387
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:
417388
418389
<div style={{marginBottom: '30px'}} align="center">
419390
<img src="/img/tutorials/quick-start/multi-contract.png" alt="Multi-contract scheme"/>
420-
</div>
391+
</div> */}
421392

422393
Verify that all examples are correct by running the test script:
423394

@@ -430,15 +401,24 @@ Expected output should look like this:
430401
```bash
431402
PASS tests/HelloWorld.spec.ts
432403
HelloWorld
433-
✓ should correctly initialize and return the initial data (446 ms)
434-
✓ should send an external message and update counter (209 ms)
435-
✓ should increase counter (298 ms)
404+
✓ should receive external message and update counter (251 ms)
436405

437406
Test Suites: 1 passed, 1 total
438-
Tests: 3 passed, 3 total
407+
Tests: 1 passed, 1 total
439408
Snapshots: 0 total
440-
Time: 3.663 s, estimated 4 s
441-
Ran all test suites matching /HelloWorld/i.
409+
Time: 1.841 s, estimated 2 s
410+
Ran all test suites.
411+
442412
```
443413

414+
## Next step
415+
416+
Now that you understand how smart contracts send and receive messages, you can **deploy your contract** to TON Blockchain.
417+
418+
<Button href="/v3/guidelines/quick-start/developing-smart-contracts/func-tolk-folder/deploying-to-network" colorType={'primary'} sizeType={'sm'}>
419+
420+
Deploying to network
421+
422+
</Button>
423+
444424
<Feedback />

0 commit comments

Comments
 (0)