From 05ba90e4a7e36fee6d388e4dd64dcdaf3be333b0 Mon Sep 17 00:00:00 2001 From: danko Date: Sat, 28 Oct 2023 00:44:23 +0700 Subject: [PATCH] docs libraries migration --- 01-wallet/index.md | 2 +- 02-contract/index.md | 36 ++++++++--------- 03-client/index.md | 12 +++--- HELP.md | 2 +- docs/01-wallet/index.html | 32 +++++++-------- docs/01-wallet/mainnet-npmton.html | 2 +- docs/01-wallet/mainnet-npmton.md | 2 +- docs/01-wallet/testnet-npmton.html | 2 +- docs/01-wallet/testnet-npmton.md | 2 +- docs/02-contract/index.html | 58 ++++++++++++++-------------- docs/02-contract/mainnet-npmton.html | 18 ++++----- docs/02-contract/mainnet-npmton.md | 26 ++++++------- docs/02-contract/testnet-npmton.html | 18 ++++----- docs/02-contract/testnet-npmton.md | 26 ++++++------- docs/03-client/index.html | 30 +++++++------- docs/03-client/mainnet-npmton.html | 4 +- docs/03-client/mainnet-npmton.md | 10 ++--- docs/03-client/testnet-npmton.html | 4 +- docs/03-client/testnet-npmton.md | 10 ++--- 19 files changed, 148 insertions(+), 148 deletions(-) diff --git a/01-wallet/index.md b/01-wallet/index.md index e346bfd..70b0200 100644 --- a/01-wallet/index.md +++ b/01-wallet/index.md @@ -128,7 +128,7 @@ npm install ts-node --- library:npmton --- -Next, we're going to install a JavaScript package named [ton](https://www.npmjs.com/package/ton) that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running: +Next, we're going to install a JavaScript package named [@ton/ton](https://www.npmjs.com/package/@ton/ton) that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running: ```console npm install @ton/ton @ton/crypto @ton/core diff --git a/02-contract/index.md b/02-contract/index.md index d6d0f84..b3bb389 100644 --- a/02-contract/index.md +++ b/02-contract/index.md @@ -82,7 +82,7 @@ Let's start with the first section, *storage*, and implement two utility functio } () save_data(int counter) impure inline { ;; write function declaration - takes an int as arg - set_data(begin_cell() ;; store the storage cell and create it with a builder + set_data(begin_cell() ;; store the storage cell and create it with a builder .store_uint(counter, 64) ;; write a 64 bit unsigned int to the builder .end_cell()); ;; convert the builder to a cell } @@ -130,14 +130,14 @@ That's it. We completed our 3 sections and the first version of our contract is ## Step 6: Build the counter contract -Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM [bytecode](https://ton.org/docs/learn/tvm-instructions/instructions). +Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM [bytecode](https://ton.org/docs/learn/tvm-instructions/instructions). In TON, we don't compile FunC directly to bytecode, but instead go through another programming language called [Fift](https://ton-blockchain.github.io/docs/fiftbase.pdf). Just like FunC, Fift is another language that was designed specifically for TON Blockchain. It's a low level language that is very close to TVM opcodes. For us regular mortals, Fift is not very useful, so unless you're planning on some extra advanced things, I believe you can safely ignore it for now. Since we're using func-js for building, it would be a good idea to create a directory where we can store the build result. To do this, open the terminal and run the following command: ```console -mkdir build +mkdir build ``` The func-js package contains everything we need to compile our contract to bytecode. To use it, open terminal in the project directory and run the following: @@ -166,7 +166,7 @@ The recommended way to interact with contracts is to create a small TypeScript c Use the following code in `wrappers/Counter.ts` to create the initial data cell for deployment: ```ts -import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core"; +import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core"; export default class Counter implements Contract { @@ -178,12 +178,12 @@ export default class Counter implements Contract { const address = contractAddress(workchain, { code, data }); return new Counter(address, { code, data }); } - + constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {} } ``` -Notice a few interesting things about this TypeScript code. First, it depends on the package [ton-core](https://www.npmjs.com/package/ton-core) instead of [ton](https://www.npmjs.com/package/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`. +Notice a few interesting things about this TypeScript code. First, it depends on the package [@ton/core](https://www.npmjs.com/package/@ton/core) instead of [@ton/ton](https://www.npmjs.com/package/@ton/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`. The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function `sendDeploy()` to `wrappers/Counter.ts` - this function will send the deployment message: @@ -227,7 +227,7 @@ network:testnet import * as fs from "fs"; import { getHttpEndpoint } from "@orbs-network/ton-access"; import { mnemonicToWalletKey } from "ton-crypto"; -import { TonClient, Cell, WalletContractV4 } from "ton"; +import { TonClient, Cell, WalletContractV4 } from "@ton/ton"; import Counter from "../wrappers/Counter"; // this is the interface class from step 7 export async function run() { @@ -239,7 +239,7 @@ export async function run() { const counterCode = Cell.fromBoc(fs.readFileSync("build/counter.cell"))[0]; // compilation output from step 6 const initialCounterValue = Date.now(); // to avoid collisions use current number of milliseconds since epoch as initial value const counter = Counter.createForDeploy(counterCode, initialCounterValue); - + // exit if contract is already deployed console.log("contract address:", counter.address.toString()); if (await client.isContractDeployed(counter.address)) { @@ -258,7 +258,7 @@ export async function run() { const walletContract = client.open(wallet); const walletSender = walletContract.sender(key.secretKey); const seqno = await walletContract.getSeqno(); - + // send the deploy transaction const counterContract = client.open(counter); await counterContract.sendDeploy(walletSender); @@ -287,7 +287,7 @@ network:mainnet import * as fs from "fs"; import { getHttpEndpoint } from "@orbs-network/ton-access"; import { mnemonicToWalletKey } from "ton-crypto"; -import { TonClient, Cell, WalletContractV4 } from "ton"; +import { TonClient, Cell, WalletContractV4 } from "@ton/ton"; import Counter from "../wrappers/Counter"; // this is the interface class from step 7 export async function run() { @@ -299,7 +299,7 @@ export async function run() { const counterCode = Cell.fromBoc(fs.readFileSync("build/counter.cell"))[0]; // compilation output from step 6 const initialCounterValue = Date.now(); // to avoid collisions use current number of milliseconds since epoch as initial value const counter = Counter.createForDeploy(counterCode, initialCounterValue); - + // exit if contract is already deployed console.log("contract address:", counter.address.toString()); if (await client.isContractDeployed(counter.address)) { @@ -318,7 +318,7 @@ export async function run() { const walletContract = client.open(wallet); const walletSender = walletContract.sender(key.secretKey); const seqno = await walletContract.getSeqno(); - + // send the deploy transaction const counterContract = client.open(counter); await counterContract.sendDeploy(walletSender); @@ -393,7 +393,7 @@ Add the following to `wrappers/Counter.ts`: // } ``` -Notice that methods in the interface class that call getters must start with the word `get`. This prefix is a requirement of the [ton](https://www.npmjs.com/package/ton) TypeScript library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step9.ts). +Notice that methods in the interface class that call getters must start with the word `get`. This prefix is a requirement of the [@ton/ton](https://www.npmjs.com/package/@ton/ton) TypeScript library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step9.ts). ### Executing the call @@ -406,7 +406,7 @@ network:testnet --- ```ts import { getHttpEndpoint } from "@orbs-network/ton-access"; -import { TonClient, Address } from "ton"; +import { TonClient, Address } from "@ton/ton"; import Counter from "../wrappers/Counter"; // this is the interface class we just implemented export async function run() { @@ -432,7 +432,7 @@ network:mainnet --- ```ts import { getHttpEndpoint } from "@orbs-network/ton-access"; -import { TonClient, Address } from "ton"; +import { TonClient, Address } from "@ton/ton"; import Counter from "../wrappers/Counter"; // this is the interface class we just implemented export async function run() { @@ -490,7 +490,7 @@ Add the following to `wrappers/Counter.ts`: As you recall, the increment message is an [internal message](https://ton.org/docs/develop/smart-contracts/guidelines/internal-messages) that is encoded by convention with a 32 bit unsigned int in the beginning to describe the op and a 64 bit unsigned int after to describe the query id. The query id is relevant for messages that expect a response message to be sent back (the request and the response share the same query id). -Notice that methods in the interface class that send messages must start with the word `send`, another prefix requirement of the [ton](https://www.npmjs.com/package/ton) library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step10.ts). +Notice that methods in the interface class that send messages must start with the word `send`, another prefix requirement of the [@ton/ton](https://www.npmjs.com/package/@ton/ton) library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step10.ts). ### Executing the send @@ -502,7 +502,7 @@ network:testnet ```ts import { getHttpEndpoint } from "@orbs-network/ton-access"; import { mnemonicToWalletKey } from "ton-crypto"; -import { TonClient, WalletContractV4, Address } from "ton"; +import { TonClient, WalletContractV4, Address } from "@ton/ton"; import Counter from "../wrappers/Counter"; // this is the interface class we just implemented export async function run() { @@ -554,7 +554,7 @@ network:mainnet ```ts import { getHttpEndpoint } from "@orbs-network/ton-access"; import { mnemonicToWalletKey } from "ton-crypto"; -import { TonClient, WalletContractV4, Address } from "ton"; +import { TonClient, WalletContractV4, Address } from "@ton/ton"; import Counter from "../wrappers/Counter"; // this is the interface class we just implemented export async function run() { diff --git a/03-client/index.md b/03-client/index.md index 1e04f9e..e6bd16a 100644 --- a/03-client/index.md +++ b/03-client/index.md @@ -42,7 +42,7 @@ npm install @ton/ton @ton/core @ton/crypto npm install @orbs-network/ton-access ``` -Last but not least, we will need to overcome [ton](https://www.npmjs.com/package/ton) library's reliance on Nodejs `Buffer` that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal: +Last but not least, we will need to overcome [@ton/ton](https://www.npmjs.com/package/@ton/ton) library's reliance on Nodejs `Buffer` that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal: ```console npm install vite-plugin-node-polyfills @@ -165,7 +165,7 @@ network:testnet --- ```ts import { getHttpEndpoint } from '@orbs-network/ton-access'; -import { TonClient } from 'ton'; +import { TonClient } from "@ton/ton"; import { useAsyncInitialize } from './useAsyncInitialize'; export function useTonClient() { @@ -185,7 +185,7 @@ network:mainnet --- ```ts import { getHttpEndpoint } from '@orbs-network/ton-access'; -import { TonClient } from 'ton'; +import { TonClient } from "@ton/ton"; import { useAsyncInitialize } from './useAsyncInitialize'; export function useTonClient() { @@ -214,7 +214,7 @@ import { Address, OpenedContract } from '@ton/core'; export function useCounterContract() { const client = useTonClient(); const [val, setVal] = useState(); - + const counterContract = useAsyncInitialize(async () => { if (!client) return; const contract = new Counter( @@ -335,7 +335,7 @@ export function useCounterContract() { const { sender } = useTonConnect(); const sleep = (time: number) => new Promise((resolve) => setTimeout(resolve, time)); - + const counterContract = useAsyncInitialize(async () => { if (!client) return; const contract = new Counter( @@ -415,7 +415,7 @@ Time to rebuild the web app, run in terminal: npm run dev ``` -Then refresh the web browser viewing the URL shown on-screen. You should see a new "Increment" link on the bottom of the screen. I'm assuming that you're still on desktop, make a note of the counter value and click the link. +Then refresh the web browser viewing the URL shown on-screen. You should see a new "Increment" link on the bottom of the screen. I'm assuming that you're still on desktop, make a note of the counter value and click the link. Since your mobile Tonkeeper wallet is connected, this action should reach the Tonkeeper mobile app and cause it to display a confirmation dialog. Notice that this dialog shows the gas cost of the transaction. Approve the transaction on the mobile app. Since the app and wallet are connected, your approval should reach the app and cause it to display an indication that the transaction was sent. As you recall, new transactions must wait until they're included in a block, so this should take 5-10 seconds. diff --git a/HELP.md b/HELP.md index 585378e..6f10637 100644 --- a/HELP.md +++ b/HELP.md @@ -8,7 +8,7 @@ If something in the tutorial isn't working, these are the possible causes: The bottom of every tutorial contains a link to the full code of all steps (in the *Conclusion* section). The code is written as an automated test that we run a few times a week. Compare your code to the test code and try to find where you did something different. - A common mistake is trying to send transactions from a wallet contract that isn't deployed or funded. This can happen if you're setting the wrong wallet version. As explained in the first tutorial, check your wallet address in an explorer and if your wallet has a different version from "wallet v4 r2" you will need to modify the example code. Let's say for example that your version is "wallet v3 r2" and you're using [ton](https://www.npmjs.com/package/ton) library, then replace `WalletContractV4` with `WalletContractV3R2`. + A common mistake is trying to send transactions from a wallet contract that isn't deployed or funded. This can happen if you're setting the wrong wallet version. As explained in the first tutorial, check your wallet address in an explorer and if your wallet has a different version from "wallet v4 r2" you will need to modify the example code. Let's say for example that your version is "wallet v3 r2" and you're using [@ton/ton](https://www.npmjs.com/package/@ton/ton) library, then replace `WalletContractV4` with `WalletContractV3R2`. 2. **One of the libraries we depend on had a breaking change and the tutorial is out of date.** diff --git a/docs/01-wallet/index.html b/docs/01-wallet/index.html index 13747d2..06cd4de 100644 --- a/docs/01-wallet/index.html +++ b/docs/01-wallet/index.html @@ -25,7 +25,7 @@
- +

TON Hello World part 1: Step by step guide for working with your first TON wallet

@@ -171,7 +171,7 @@

Step 6: Set up your local machine f

Let's create a new directory for our project and support TypeScript. Open terminal in the project directory and run the following:

npm install ts-node
 
-

Next, we're going to install a JavaScript package named ton that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

+

Next, we're going to install a JavaScript package named ton that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

npm install @ton/ton @ton/crypto @ton/core
 

Step 7: Get the wallet address programmatically

@@ -306,7 +306,7 @@

Conclusion

If you found a mistake in this tutorial, please submit a PR and help us fix it. This tutorial platform is fully open source and available on https://github.com/ton-community/tutorials.

Happy coding!

- +

TON Hello World part 1: Step by step guide for working with your first TON wallet

@@ -499,7 +499,7 @@

Conclusion

If you found a mistake in this tutorial, please submit a PR and help us fix it. This tutorial platform is fully open source and available on https://github.com/ton-community/tutorials.

Happy coding!

- +

TON Hello World part 1: Step by step guide for working with your first TON wallet

@@ -561,7 +561,7 @@

Step 6: Set up your local machine f

Let's create a new directory for our project and support TypeScript. Open terminal in the project directory and run the following:

npm install ts-node
 
-

Next, we're going to install a JavaScript package named ton that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

+

Next, we're going to install a JavaScript package named ton that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

npm install @ton/ton @ton/crypto @ton/core
 

Step 7: Get the wallet address programmatically

@@ -696,7 +696,7 @@

Conclusion

If you found a mistake in this tutorial, please submit a PR and help us fix it. This tutorial platform is fully open source and available on https://github.com/ton-community/tutorials.

Happy coding!

- +

TON Hello World part 1: Step by step guide for working with your first TON wallet

@@ -891,7 +891,7 @@

Conclusion

If you found a mistake in this tutorial, please submit a PR and help us fix it. This tutorial platform is fully open source and available on https://github.com/ton-community/tutorials.

Happy coding!

- +
diff --git a/docs/01-wallet/mainnet-npmton.html b/docs/01-wallet/mainnet-npmton.html index 5f8e0b6..aef6eb8 100644 --- a/docs/01-wallet/mainnet-npmton.html +++ b/docs/01-wallet/mainnet-npmton.html @@ -48,7 +48,7 @@

Step 6: Set up your local machine f

Let's create a new directory for our project and support TypeScript. Open terminal in the project directory and run the following:

npm install ts-node
 
-

Next, we're going to install a JavaScript package named ton that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

+

Next, we're going to install a JavaScript package named ton that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

npm install @ton/ton @ton/crypto @ton/core
 

Step 7: Get the wallet address programmatically

diff --git a/docs/01-wallet/mainnet-npmton.md b/docs/01-wallet/mainnet-npmton.md index 6c771cc..2c7cb48 100644 --- a/docs/01-wallet/mainnet-npmton.md +++ b/docs/01-wallet/mainnet-npmton.md @@ -99,7 +99,7 @@ Let's create a new directory for our project and support TypeScript. Open termin npm install ts-node ``` -Next, we're going to install a JavaScript package named [ton](https://www.npmjs.com/package/ton) that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running: +Next, we're going to install a JavaScript package named [@ton/ton](https://www.npmjs.com/package/@ton/ton) that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running: ```console npm install @ton/ton @ton/crypto @ton/core diff --git a/docs/01-wallet/testnet-npmton.html b/docs/01-wallet/testnet-npmton.html index 2b9cb23..a5d6c40 100644 --- a/docs/01-wallet/testnet-npmton.html +++ b/docs/01-wallet/testnet-npmton.html @@ -50,7 +50,7 @@

Step 6: Set up your local machine f

Let's create a new directory for our project and support TypeScript. Open terminal in the project directory and run the following:

npm install ts-node
 
-

Next, we're going to install a JavaScript package named ton that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

+

Next, we're going to install a JavaScript package named ton that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

npm install @ton/ton @ton/crypto @ton/core
 

Step 7: Get the wallet address programmatically

diff --git a/docs/01-wallet/testnet-npmton.md b/docs/01-wallet/testnet-npmton.md index 9484cab..c147f5f 100644 --- a/docs/01-wallet/testnet-npmton.md +++ b/docs/01-wallet/testnet-npmton.md @@ -103,7 +103,7 @@ Let's create a new directory for our project and support TypeScript. Open termin npm install ts-node ``` -Next, we're going to install a JavaScript package named [ton](https://www.npmjs.com/package/ton) that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running: +Next, we're going to install a JavaScript package named [@ton/ton](https://www.npmjs.com/package/@ton/ton) that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running: ```console npm install @ton/ton @ton/crypto @ton/core diff --git a/docs/02-contract/index.html b/docs/02-contract/index.html index ec57c37..0b355e3 100644 --- a/docs/02-contract/index.html +++ b/docs/02-contract/index.html @@ -25,7 +25,7 @@
- +

TON Hello World part 2: Step by step guide for writing your first smart contract

@@ -156,7 +156,7 @@

Storage

} () save_data(int counter) impure inline { ;; write function declaration - takes an int as arg - set_data(begin_cell() ;; store the storage cell and create it with a builder + set_data(begin_cell() ;; store the storage cell and create it with a builder .store_uint(counter, 64) ;; write a 64 bit unsigned int to the builder .end_cell()); ;; convert the builder to a cell } @@ -191,7 +191,7 @@

Step 6: Build the counter contract

Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM bytecode.

In TON, we don't compile FunC directly to bytecode, but instead go through another programming language called Fift. Just like FunC, Fift is another language that was designed specifically for TON Blockchain. It's a low level language that is very close to TVM opcodes. For us regular mortals, Fift is not very useful, so unless you're planning on some extra advanced things, I believe you can safely ignore it for now.

Since we're using func-js for building, it would be a good idea to create a directory where we can store the build result. To do this, open the terminal and run the following command:

-
mkdir build 
+
mkdir build
 

The func-js package contains everything we need to compile our contract to bytecode. To use it, open terminal in the project directory and run the following:

npx func-js contracts/counter.fc --boc build/counter.cell
@@ -206,7 +206,7 @@ 

Init arguments

Interface class

The recommended way to interact with contracts is to create a small TypeScript class that will implement the interaction interface with the contract. We're using the project structure created by Blueprint, but we're still working on low-level aspects. Use the following code in wrappers/Counter.ts to create the initial data cell for deployment:

-
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
+
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";
 
 export default class Counter implements Contract {
 
@@ -222,7 +222,7 @@ 

Interface class

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {} }
-

Notice a few interesting things about this TypeScript code. First, it depends on the package ton-core instead of ton, which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our save_data() FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function contractAddress.

+

Notice a few interesting things about this TypeScript code. First, it depends on the package @ton/core instead of ton, which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our save_data() FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function contractAddress.

The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function sendDeploy() to wrappers/Counter.ts - this function will send the deployment message:

// export default class Counter implements Contract {
 
@@ -248,7 +248,7 @@ 

Step 8: Deploy the contract on-chain

import * as fs from "fs";
 import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, Cell, WalletContractV4 } from "ton";
+import { TonClient, Cell, WalletContractV4 } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class from step 7
 
 export async function run() {
@@ -321,12 +321,12 @@ 

Interface class

// }
-

Notice that methods in the interface class that call getters must start with the word get. This prefix is a requirement of the ton TypeScript library. The resulting source file should look like this.

+

Notice that methods in the interface class that call getters must start with the word get. This prefix is a requirement of the ton TypeScript library. The resulting source file should look like this.

Executing the call

Calling a getter is free and does not cost gas. The reason is that this call is read-only, so it does not require consensus by the validators and is not stored in a block on-chain for all eternity like transaction are.

Let's create a new script called getCounter.ts in the scripts folder and use our shiny interface class to make the call. We're going to emulate a different developer interacting with our contract and since the contract is already deployed, they are likely to access it by address. Be sure to replace my deployed contract address with yours in the code below:

import { getHttpEndpoint } from "@orbs-network/ton-access";
-import { TonClient, Address } from "ton";
+import { TonClient, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
@@ -369,12 +369,12 @@ 

Interface class

// }

As you recall, the increment message is an internal message that is encoded by convention with a 32 bit unsigned int in the beginning to describe the op and a 64 bit unsigned int after to describe the query id. The query id is relevant for messages that expect a response message to be sent back (the request and the response share the same query id).

-

Notice that methods in the interface class that send messages must start with the word send, another prefix requirement of the ton library. The resulting source file should look like this.

+

Notice that methods in the interface class that send messages must start with the word send, another prefix requirement of the ton library. The resulting source file should look like this.

Executing the send

The messages can be sent from any TON wallet, not necessarily the deployer wallet. Create a new script sendIncrement.ts in the scripts folder and use your wallet to fund the send:

import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, WalletContractV4, Address } from "ton";
+import { TonClient, WalletContractV4, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
@@ -437,7 +437,7 @@ 

Conclusion

If you found a mistake in this tutorial, please submit a PR and help us fix it. This tutorial platform is fully open source and available on https://github.com/ton-community/tutorials.

Happy coding!

- +

TON Hello World part 2: Step by step guide for writing your first smart contract

@@ -493,7 +493,7 @@

Storage

} () save_data(int counter) impure inline { ;; write function declaration - takes an int as arg - set_data(begin_cell() ;; store the storage cell and create it with a builder + set_data(begin_cell() ;; store the storage cell and create it with a builder .store_uint(counter, 64) ;; write a 64 bit unsigned int to the builder .end_cell()); ;; convert the builder to a cell } @@ -528,7 +528,7 @@

Step 6: Build the counter contract

Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM bytecode.

In TON, we don't compile FunC directly to bytecode, but instead go through another programming language called Fift. Just like FunC, Fift is another language that was designed specifically for TON Blockchain. It's a low level language that is very close to TVM opcodes. For us regular mortals, Fift is not very useful, so unless you're planning on some extra advanced things, I believe you can safely ignore it for now.

Since we're using func-js for building, it would be a good idea to create a directory where we can store the build result. To do this, open the terminal and run the following command:

-
mkdir build 
+
mkdir build
 

The func-js package contains everything we need to compile our contract to bytecode. To use it, open terminal in the project directory and run the following:

npx func-js contracts/counter.fc --boc build/counter.cell
@@ -543,7 +543,7 @@ 

Init arguments

Interface class

The recommended way to interact with contracts is to create a small TypeScript class that will implement the interaction interface with the contract. We're using the project structure created by Blueprint, but we're still working on low-level aspects. Use the following code in wrappers/Counter.ts to create the initial data cell for deployment:

-
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
+
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";
 
 export default class Counter implements Contract {
 
@@ -559,7 +559,7 @@ 

Interface class

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {} }
-

Notice a few interesting things about this TypeScript code. First, it depends on the package ton-core instead of ton, which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our save_data() FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function contractAddress.

+

Notice a few interesting things about this TypeScript code. First, it depends on the package @ton/core instead of ton, which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our save_data() FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function contractAddress.

The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function sendDeploy() to wrappers/Counter.ts - this function will send the deployment message:

// export default class Counter implements Contract {
 
@@ -585,7 +585,7 @@ 

Step 8: Deploy the contract on-chain

import * as fs from "fs";
 import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, Cell, WalletContractV4 } from "ton";
+import { TonClient, Cell, WalletContractV4 } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class from step 7
 
 export async function run() {
@@ -658,12 +658,12 @@ 

Interface class

// }
-

Notice that methods in the interface class that call getters must start with the word get. This prefix is a requirement of the ton TypeScript library. The resulting source file should look like this.

+

Notice that methods in the interface class that call getters must start with the word get. This prefix is a requirement of the ton TypeScript library. The resulting source file should look like this.

Executing the call

Calling a getter is free and does not cost gas. The reason is that this call is read-only, so it does not require consensus by the validators and is not stored in a block on-chain for all eternity like transaction are.

Let's create a new script called getCounter.ts in the scripts folder and use our shiny interface class to make the call. We're going to emulate a different developer interacting with our contract and since the contract is already deployed, they are likely to access it by address. Be sure to replace my deployed contract address with yours in the code below:

import { getHttpEndpoint } from "@orbs-network/ton-access";
-import { TonClient, Address } from "ton";
+import { TonClient, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
@@ -706,12 +706,12 @@ 

Interface class

// }

As you recall, the increment message is an internal message that is encoded by convention with a 32 bit unsigned int in the beginning to describe the op and a 64 bit unsigned int after to describe the query id. The query id is relevant for messages that expect a response message to be sent back (the request and the response share the same query id).

-

Notice that methods in the interface class that send messages must start with the word send, another prefix requirement of the ton library. The resulting source file should look like this.

+

Notice that methods in the interface class that send messages must start with the word send, another prefix requirement of the ton library. The resulting source file should look like this.

Executing the send

The messages can be sent from any TON wallet, not necessarily the deployer wallet. Create a new script sendIncrement.ts in the scripts folder and use your wallet to fund the send:

import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, WalletContractV4, Address } from "ton";
+import { TonClient, WalletContractV4, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
@@ -774,7 +774,7 @@ 

Conclusion

If you found a mistake in this tutorial, please submit a PR and help us fix it. This tutorial platform is fully open source and available on https://github.com/ton-community/tutorials.

Happy coding!

- +
diff --git a/docs/02-contract/mainnet-npmton.html b/docs/02-contract/mainnet-npmton.html index d5a023e..3d629a5 100644 --- a/docs/02-contract/mainnet-npmton.html +++ b/docs/02-contract/mainnet-npmton.html @@ -44,7 +44,7 @@

Storage

} () save_data(int counter) impure inline { ;; write function declaration - takes an int as arg - set_data(begin_cell() ;; store the storage cell and create it with a builder + set_data(begin_cell() ;; store the storage cell and create it with a builder .store_uint(counter, 64) ;; write a 64 bit unsigned int to the builder .end_cell()); ;; convert the builder to a cell } @@ -79,7 +79,7 @@

Step 6: Build the counter contract

Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM bytecode.

In TON, we don't compile FunC directly to bytecode, but instead go through another programming language called Fift. Just like FunC, Fift is another language that was designed specifically for TON Blockchain. It's a low level language that is very close to TVM opcodes. For us regular mortals, Fift is not very useful, so unless you're planning on some extra advanced things, I believe you can safely ignore it for now.

Since we're using func-js for building, it would be a good idea to create a directory where we can store the build result. To do this, open the terminal and run the following command:

-
mkdir build 
+
mkdir build
 

The func-js package contains everything we need to compile our contract to bytecode. To use it, open terminal in the project directory and run the following:

npx func-js contracts/counter.fc --boc build/counter.cell
@@ -94,7 +94,7 @@ 

Init arguments

Interface class

The recommended way to interact with contracts is to create a small TypeScript class that will implement the interaction interface with the contract. We're using the project structure created by Blueprint, but we're still working on low-level aspects. Use the following code in wrappers/Counter.ts to create the initial data cell for deployment:

-
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
+
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";
 
 export default class Counter implements Contract {
 
@@ -110,7 +110,7 @@ 

Interface class

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {} }
-

Notice a few interesting things about this TypeScript code. First, it depends on the package ton-core instead of ton, which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our save_data() FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function contractAddress.

+

Notice a few interesting things about this TypeScript code. First, it depends on the package @ton/core instead of ton, which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our save_data() FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function contractAddress.

The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function sendDeploy() to wrappers/Counter.ts - this function will send the deployment message:

// export default class Counter implements Contract {
 
@@ -136,7 +136,7 @@ 

Step 8: Deploy the contract on-chain

import * as fs from "fs";
 import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, Cell, WalletContractV4 } from "ton";
+import { TonClient, Cell, WalletContractV4 } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class from step 7
 
 export async function run() {
@@ -209,12 +209,12 @@ 

Interface class

// }
-

Notice that methods in the interface class that call getters must start with the word get. This prefix is a requirement of the ton TypeScript library. The resulting source file should look like this.

+

Notice that methods in the interface class that call getters must start with the word get. This prefix is a requirement of the ton TypeScript library. The resulting source file should look like this.

Executing the call

Calling a getter is free and does not cost gas. The reason is that this call is read-only, so it does not require consensus by the validators and is not stored in a block on-chain for all eternity like transaction are.

Let's create a new script called getCounter.ts in the scripts folder and use our shiny interface class to make the call. We're going to emulate a different developer interacting with our contract and since the contract is already deployed, they are likely to access it by address. Be sure to replace my deployed contract address with yours in the code below:

import { getHttpEndpoint } from "@orbs-network/ton-access";
-import { TonClient, Address } from "ton";
+import { TonClient, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
@@ -257,12 +257,12 @@ 

Interface class

// }

As you recall, the increment message is an internal message that is encoded by convention with a 32 bit unsigned int in the beginning to describe the op and a 64 bit unsigned int after to describe the query id. The query id is relevant for messages that expect a response message to be sent back (the request and the response share the same query id).

-

Notice that methods in the interface class that send messages must start with the word send, another prefix requirement of the ton library. The resulting source file should look like this.

+

Notice that methods in the interface class that send messages must start with the word send, another prefix requirement of the ton library. The resulting source file should look like this.

Executing the send

The messages can be sent from any TON wallet, not necessarily the deployer wallet. Create a new script sendIncrement.ts in the scripts folder and use your wallet to fund the send:

import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, WalletContractV4, Address } from "ton";
+import { TonClient, WalletContractV4, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
diff --git a/docs/02-contract/mainnet-npmton.md b/docs/02-contract/mainnet-npmton.md
index 7655043..0586d6f 100644
--- a/docs/02-contract/mainnet-npmton.md
+++ b/docs/02-contract/mainnet-npmton.md
@@ -82,7 +82,7 @@ Let's start with the first section, *storage*, and implement two utility functio
 }
 
 () save_data(int counter) impure inline {  ;; write function declaration - takes an int as arg
-  set_data(begin_cell()                    ;; store the storage cell and create it with a builder 
+  set_data(begin_cell()                    ;; store the storage cell and create it with a builder
     .store_uint(counter, 64)               ;; write a 64 bit unsigned int to the builder
     .end_cell());                          ;; convert the builder to a cell
 }
@@ -130,14 +130,14 @@ That's it. We completed our 3 sections and the first version of our contract is
 
 ## Step 6: Build the counter contract
 
-Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM [bytecode](https://ton.org/docs/learn/tvm-instructions/instructions). 
+Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM [bytecode](https://ton.org/docs/learn/tvm-instructions/instructions).
 
 In TON, we don't compile FunC directly to bytecode, but instead go through another programming language called [Fift](https://ton-blockchain.github.io/docs/fiftbase.pdf). Just like FunC, Fift is another language that was designed specifically for TON Blockchain. It's a low level language that is very close to TVM opcodes. For us regular mortals, Fift is not very useful, so unless you're planning on some extra advanced things, I believe you can safely ignore it for now.
 
 Since we're using func-js for building, it would be a good idea to create a directory where we can store the build result. To do this, open the terminal and run the following command:
 
 ```console
-mkdir build 
+mkdir build
 ```
 
 The func-js package contains everything we need to compile our contract to bytecode. To use it, open terminal in the project directory and run the following:
@@ -166,7 +166,7 @@ The recommended way to interact with contracts is to create a small TypeScript c
 Use the following code in `wrappers/Counter.ts` to create the initial data cell for deployment:
 
 ```ts
-import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
+import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";
 
 export default class Counter implements Contract {
 
@@ -178,12 +178,12 @@ export default class Counter implements Contract {
     const address = contractAddress(workchain, { code, data });
     return new Counter(address, { code, data });
   }
-  
+
   constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {}
 }
 ```
 
-Notice a few interesting things about this TypeScript code. First, it depends on the package [ton-core](https://www.npmjs.com/package/ton-core) instead of [ton](https://www.npmjs.com/package/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`.
+Notice a few interesting things about this TypeScript code. First, it depends on the package [@ton/core](https://www.npmjs.com/package/@ton/core) instead of [@ton/ton](https://www.npmjs.com/package/@ton/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`.
 
 The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function `sendDeploy()` to `wrappers/Counter.ts` - this function will send the deployment message:
 
@@ -224,7 +224,7 @@ Replace the current code in `scripts/deployCounter.ts` with a script that will u
 import * as fs from "fs";
 import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, Cell, WalletContractV4 } from "ton";
+import { TonClient, Cell, WalletContractV4 } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class from step 7
 
 export async function run() {
@@ -236,7 +236,7 @@ export async function run() {
   const counterCode = Cell.fromBoc(fs.readFileSync("build/counter.cell"))[0]; // compilation output from step 6
   const initialCounterValue = Date.now(); // to avoid collisions use current number of milliseconds since epoch as initial value
   const counter = Counter.createForDeploy(counterCode, initialCounterValue);
-  
+
   // exit if contract is already deployed
   console.log("contract address:", counter.address.toString());
   if (await client.isContractDeployed(counter.address)) {
@@ -255,7 +255,7 @@ export async function run() {
   const walletContract = client.open(wallet);
   const walletSender = walletContract.sender(key.secretKey);
   const seqno = await walletContract.getSeqno();
-  
+
   // send the deploy transaction
   const counterContract = client.open(counter);
   await counterContract.sendDeploy(walletSender);
@@ -314,7 +314,7 @@ Add the following to `wrappers/Counter.ts`:
 // }
 ```
 
-Notice that methods in the interface class that call getters must start with the word `get`. This prefix is a requirement of the [ton](https://www.npmjs.com/package/ton) TypeScript library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step9.ts).
+Notice that methods in the interface class that call getters must start with the word `get`. This prefix is a requirement of the [@ton/ton](https://www.npmjs.com/package/@ton/ton) TypeScript library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step9.ts).
 
 ### Executing the call
 
@@ -324,7 +324,7 @@ Let's create a new script called `getCounter.ts` in the `scripts` folder and use
 
 ```ts
 import { getHttpEndpoint } from "@orbs-network/ton-access";
-import { TonClient, Address } from "ton";
+import { TonClient, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
@@ -380,7 +380,7 @@ Add the following to `wrappers/Counter.ts`:
 
 As you recall, the increment message is an [internal message](https://ton.org/docs/develop/smart-contracts/guidelines/internal-messages) that is encoded by convention with a 32 bit unsigned int in the beginning to describe the op and a 64 bit unsigned int after to describe the query id. The query id is relevant for messages that expect a response message to be sent back (the request and the response share the same query id).
 
-Notice that methods in the interface class that send messages must start with the word `send`, another prefix requirement of the [ton](https://www.npmjs.com/package/ton) library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step10.ts).
+Notice that methods in the interface class that send messages must start with the word `send`, another prefix requirement of the [@ton/ton](https://www.npmjs.com/package/@ton/ton) library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step10.ts).
 
 ### Executing the send
 
@@ -389,7 +389,7 @@ The messages can be sent from any TON wallet, not necessarily the deployer walle
 ```ts
 import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, WalletContractV4, Address } from "ton";
+import { TonClient, WalletContractV4, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
diff --git a/docs/02-contract/testnet-npmton.html b/docs/02-contract/testnet-npmton.html
index eaf8644..0b7582d 100644
--- a/docs/02-contract/testnet-npmton.html
+++ b/docs/02-contract/testnet-npmton.html
@@ -44,7 +44,7 @@ 

Storage

} () save_data(int counter) impure inline { ;; write function declaration - takes an int as arg - set_data(begin_cell() ;; store the storage cell and create it with a builder + set_data(begin_cell() ;; store the storage cell and create it with a builder .store_uint(counter, 64) ;; write a 64 bit unsigned int to the builder .end_cell()); ;; convert the builder to a cell } @@ -79,7 +79,7 @@

Step 6: Build the counter contract

Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM bytecode.

In TON, we don't compile FunC directly to bytecode, but instead go through another programming language called Fift. Just like FunC, Fift is another language that was designed specifically for TON Blockchain. It's a low level language that is very close to TVM opcodes. For us regular mortals, Fift is not very useful, so unless you're planning on some extra advanced things, I believe you can safely ignore it for now.

Since we're using func-js for building, it would be a good idea to create a directory where we can store the build result. To do this, open the terminal and run the following command:

-
mkdir build 
+
mkdir build
 

The func-js package contains everything we need to compile our contract to bytecode. To use it, open terminal in the project directory and run the following:

npx func-js contracts/counter.fc --boc build/counter.cell
@@ -94,7 +94,7 @@ 

Init arguments

Interface class

The recommended way to interact with contracts is to create a small TypeScript class that will implement the interaction interface with the contract. We're using the project structure created by Blueprint, but we're still working on low-level aspects. Use the following code in wrappers/Counter.ts to create the initial data cell for deployment:

-
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
+
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";
 
 export default class Counter implements Contract {
 
@@ -110,7 +110,7 @@ 

Interface class

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {} }
-

Notice a few interesting things about this TypeScript code. First, it depends on the package ton-core instead of ton, which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our save_data() FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function contractAddress.

+

Notice a few interesting things about this TypeScript code. First, it depends on the package @ton/core instead of ton, which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our save_data() FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function contractAddress.

The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function sendDeploy() to wrappers/Counter.ts - this function will send the deployment message:

// export default class Counter implements Contract {
 
@@ -136,7 +136,7 @@ 

Step 8: Deploy the contract on-chain

import * as fs from "fs";
 import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, Cell, WalletContractV4 } from "ton";
+import { TonClient, Cell, WalletContractV4 } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class from step 7
 
 export async function run() {
@@ -209,12 +209,12 @@ 

Interface class

// }
-

Notice that methods in the interface class that call getters must start with the word get. This prefix is a requirement of the ton TypeScript library. The resulting source file should look like this.

+

Notice that methods in the interface class that call getters must start with the word get. This prefix is a requirement of the ton TypeScript library. The resulting source file should look like this.

Executing the call

Calling a getter is free and does not cost gas. The reason is that this call is read-only, so it does not require consensus by the validators and is not stored in a block on-chain for all eternity like transaction are.

Let's create a new script called getCounter.ts in the scripts folder and use our shiny interface class to make the call. We're going to emulate a different developer interacting with our contract and since the contract is already deployed, they are likely to access it by address. Be sure to replace my deployed contract address with yours in the code below:

import { getHttpEndpoint } from "@orbs-network/ton-access";
-import { TonClient, Address } from "ton";
+import { TonClient, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
@@ -257,12 +257,12 @@ 

Interface class

// }

As you recall, the increment message is an internal message that is encoded by convention with a 32 bit unsigned int in the beginning to describe the op and a 64 bit unsigned int after to describe the query id. The query id is relevant for messages that expect a response message to be sent back (the request and the response share the same query id).

-

Notice that methods in the interface class that send messages must start with the word send, another prefix requirement of the ton library. The resulting source file should look like this.

+

Notice that methods in the interface class that send messages must start with the word send, another prefix requirement of the ton library. The resulting source file should look like this.

Executing the send

The messages can be sent from any TON wallet, not necessarily the deployer wallet. Create a new script sendIncrement.ts in the scripts folder and use your wallet to fund the send:

import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, WalletContractV4, Address } from "ton";
+import { TonClient, WalletContractV4, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
diff --git a/docs/02-contract/testnet-npmton.md b/docs/02-contract/testnet-npmton.md
index b2c438f..3ced54b 100644
--- a/docs/02-contract/testnet-npmton.md
+++ b/docs/02-contract/testnet-npmton.md
@@ -82,7 +82,7 @@ Let's start with the first section, *storage*, and implement two utility functio
 }
 
 () save_data(int counter) impure inline {  ;; write function declaration - takes an int as arg
-  set_data(begin_cell()                    ;; store the storage cell and create it with a builder 
+  set_data(begin_cell()                    ;; store the storage cell and create it with a builder
     .store_uint(counter, 64)               ;; write a 64 bit unsigned int to the builder
     .end_cell());                          ;; convert the builder to a cell
 }
@@ -130,14 +130,14 @@ That's it. We completed our 3 sections and the first version of our contract is
 
 ## Step 6: Build the counter contract
 
-Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM [bytecode](https://ton.org/docs/learn/tvm-instructions/instructions). 
+Right now, the contract is just FunC source code. To get it to run on-chain, we need to convert it to TVM [bytecode](https://ton.org/docs/learn/tvm-instructions/instructions).
 
 In TON, we don't compile FunC directly to bytecode, but instead go through another programming language called [Fift](https://ton-blockchain.github.io/docs/fiftbase.pdf). Just like FunC, Fift is another language that was designed specifically for TON Blockchain. It's a low level language that is very close to TVM opcodes. For us regular mortals, Fift is not very useful, so unless you're planning on some extra advanced things, I believe you can safely ignore it for now.
 
 Since we're using func-js for building, it would be a good idea to create a directory where we can store the build result. To do this, open the terminal and run the following command:
 
 ```console
-mkdir build 
+mkdir build
 ```
 
 The func-js package contains everything we need to compile our contract to bytecode. To use it, open terminal in the project directory and run the following:
@@ -166,7 +166,7 @@ The recommended way to interact with contracts is to create a small TypeScript c
 Use the following code in `wrappers/Counter.ts` to create the initial data cell for deployment:
 
 ```ts
-import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
+import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";
 
 export default class Counter implements Contract {
 
@@ -178,12 +178,12 @@ export default class Counter implements Contract {
     const address = contractAddress(workchain, { code, data });
     return new Counter(address, { code, data });
   }
-  
+
   constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {}
 }
 ```
 
-Notice a few interesting things about this TypeScript code. First, it depends on the package [ton-core](https://www.npmjs.com/package/ton-core) instead of [ton](https://www.npmjs.com/package/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`.
+Notice a few interesting things about this TypeScript code. First, it depends on the package [@ton/core](https://www.npmjs.com/package/@ton/core) instead of [@ton/ton](https://www.npmjs.com/package/@ton/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`.
 
 The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function `sendDeploy()` to `wrappers/Counter.ts` - this function will send the deployment message:
 
@@ -224,7 +224,7 @@ Replace the current code in `scripts/deployCounter.ts` with a script that will u
 import * as fs from "fs";
 import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, Cell, WalletContractV4 } from "ton";
+import { TonClient, Cell, WalletContractV4 } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class from step 7
 
 export async function run() {
@@ -236,7 +236,7 @@ export async function run() {
   const counterCode = Cell.fromBoc(fs.readFileSync("build/counter.cell"))[0]; // compilation output from step 6
   const initialCounterValue = Date.now(); // to avoid collisions use current number of milliseconds since epoch as initial value
   const counter = Counter.createForDeploy(counterCode, initialCounterValue);
-  
+
   // exit if contract is already deployed
   console.log("contract address:", counter.address.toString());
   if (await client.isContractDeployed(counter.address)) {
@@ -255,7 +255,7 @@ export async function run() {
   const walletContract = client.open(wallet);
   const walletSender = walletContract.sender(key.secretKey);
   const seqno = await walletContract.getSeqno();
-  
+
   // send the deploy transaction
   const counterContract = client.open(counter);
   await counterContract.sendDeploy(walletSender);
@@ -314,7 +314,7 @@ Add the following to `wrappers/Counter.ts`:
 // }
 ```
 
-Notice that methods in the interface class that call getters must start with the word `get`. This prefix is a requirement of the [ton](https://www.npmjs.com/package/ton) TypeScript library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step9.ts).
+Notice that methods in the interface class that call getters must start with the word `get`. This prefix is a requirement of the [@ton/ton](https://www.npmjs.com/package/@ton/ton) TypeScript library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step9.ts).
 
 ### Executing the call
 
@@ -324,7 +324,7 @@ Let's create a new script called `getCounter.ts` in the `scripts` folder and use
 
 ```ts
 import { getHttpEndpoint } from "@orbs-network/ton-access";
-import { TonClient, Address } from "ton";
+import { TonClient, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
@@ -380,7 +380,7 @@ Add the following to `wrappers/Counter.ts`:
 
 As you recall, the increment message is an [internal message](https://ton.org/docs/develop/smart-contracts/guidelines/internal-messages) that is encoded by convention with a 32 bit unsigned int in the beginning to describe the op and a 64 bit unsigned int after to describe the query id. The query id is relevant for messages that expect a response message to be sent back (the request and the response share the same query id).
 
-Notice that methods in the interface class that send messages must start with the word `send`, another prefix requirement of the [ton](https://www.npmjs.com/package/ton) library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step10.ts).
+Notice that methods in the interface class that send messages must start with the word `send`, another prefix requirement of the [@ton/ton](https://www.npmjs.com/package/@ton/ton) library. The resulting source file should look like [this](https://github.com/ton-community/tutorials/blob/main/02-contract/test/counter.step10.ts).
 
 ### Executing the send
 
@@ -389,7 +389,7 @@ The messages can be sent from any TON wallet, not necessarily the deployer walle
 ```ts
 import { getHttpEndpoint } from "@orbs-network/ton-access";
 import { mnemonicToWalletKey } from "ton-crypto";
-import { TonClient, WalletContractV4, Address } from "ton";
+import { TonClient, WalletContractV4, Address } from "@ton/ton";
 import Counter from "../wrappers/Counter"; // this is the interface class we just implemented
 
 export async function run() {
diff --git a/docs/03-client/index.html b/docs/03-client/index.html
index 1181797..05cadb2 100644
--- a/docs/03-client/index.html
+++ b/docs/03-client/index.html
@@ -25,7 +25,7 @@
       
- +

TON Hello World part 3: Step by step guide for building your first web client

@@ -134,7 +134,7 @@

Step 3: Set up the project

npm install @ton/ton @ton/core @ton/crypto
 npm install @orbs-network/ton-access
 
-

Last but not least, we will need to overcome ton library's reliance on Nodejs Buffer that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:

+

Last but not least, we will need to overcome ton library's reliance on Nodejs Buffer that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:

npm install vite-plugin-node-polyfills
 

Now modify the file vite.config.ts so it looks like this:

@@ -215,7 +215,7 @@

Step 6: Read the counter value fro

Next, we're going to create another React hook that will rely on useAsyncInitialize and will initialize an RPC client in our app. An RPC service provider similar to Infura on Ethereum will allow us to query data from the chain. These providers run TON Blockchain nodes and allow us to communicate with them over HTTP. TON Access is an awesome service that will provide us with unthrottled API access for free. It's also decentralized, which is the preferred way to access the network.

Create the file src/hooks/useTonClient.ts with the following content:

import { getHttpEndpoint } from '@orbs-network/ton-access';
-import { TonClient } from 'ton';
+import { TonClient } from "@ton/ton";
 import { useAsyncInitialize } from './useAsyncInitialize';
 
 export function useTonClient() {
@@ -568,7 +568,7 @@ 

Conclusion

If you found a mistake in this tutorial, please submit a PR and help us fix it. This tutorial platform is fully open source and available on https://github.com/ton-community/tutorials.

Happy coding!

- +

TON Hello World part 3: Step by step guide for building your first web client

@@ -602,7 +602,7 @@

Step 3: Set up the project

npm install @ton/ton @ton/core @ton/crypto
 npm install @orbs-network/ton-access
 
-

Last but not least, we will need to overcome ton library's reliance on Nodejs Buffer that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:

+

Last but not least, we will need to overcome ton library's reliance on Nodejs Buffer that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:

npm install vite-plugin-node-polyfills
 

Now modify the file vite.config.ts so it looks like this:

@@ -683,7 +683,7 @@

Step 6: Read the counter value fro

Next, we're going to create another React hook that will rely on useAsyncInitialize and will initialize an RPC client in our app. An RPC service provider similar to Infura on Ethereum will allow us to query data from the chain. These providers run TON Blockchain nodes and allow us to communicate with them over HTTP. TON Access is an awesome service that will provide us with unthrottled API access for free. It's also decentralized, which is the preferred way to access the network.

Create the file src/hooks/useTonClient.ts with the following content:

import { getHttpEndpoint } from '@orbs-network/ton-access';
-import { TonClient } from 'ton';
+import { TonClient } from "@ton/ton";
 import { useAsyncInitialize } from './useAsyncInitialize';
 
 export function useTonClient() {
@@ -1036,7 +1036,7 @@ 

Conclusion

If you found a mistake in this tutorial, please submit a PR and help us fix it. This tutorial platform is fully open source and available on https://github.com/ton-community/tutorials.

Happy coding!

- +
diff --git a/docs/03-client/mainnet-npmton.html b/docs/03-client/mainnet-npmton.html index ff5604e..4fa6fe9 100644 --- a/docs/03-client/mainnet-npmton.html +++ b/docs/03-client/mainnet-npmton.html @@ -22,7 +22,7 @@

Step 3: Set up the project

npm install @ton/ton @ton/core @ton/crypto
 npm install @orbs-network/ton-access
 
-

Last but not least, we will need to overcome ton library's reliance on Nodejs Buffer that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:

+

Last but not least, we will need to overcome ton library's reliance on Nodejs Buffer that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:

npm install vite-plugin-node-polyfills
 

Now modify the file vite.config.ts so it looks like this:

@@ -103,7 +103,7 @@

Step 6: Read the counter value fro

Next, we're going to create another React hook that will rely on useAsyncInitialize and will initialize an RPC client in our app. An RPC service provider similar to Infura on Ethereum will allow us to query data from the chain. These providers run TON Blockchain nodes and allow us to communicate with them over HTTP. TON Access is an awesome service that will provide us with unthrottled API access for free. It's also decentralized, which is the preferred way to access the network.

Create the file src/hooks/useTonClient.ts with the following content:

import { getHttpEndpoint } from '@orbs-network/ton-access';
-import { TonClient } from 'ton';
+import { TonClient } from "@ton/ton";
 import { useAsyncInitialize } from './useAsyncInitialize';
 
 export function useTonClient() {
diff --git a/docs/03-client/mainnet-npmton.md b/docs/03-client/mainnet-npmton.md
index 8d12f33..002a521 100644
--- a/docs/03-client/mainnet-npmton.md
+++ b/docs/03-client/mainnet-npmton.md
@@ -42,7 +42,7 @@ npm install @ton/ton @ton/core @ton/crypto
 npm install @orbs-network/ton-access
 ```
 
-Last but not least, we will need to overcome [ton](https://www.npmjs.com/package/ton) library's reliance on Nodejs `Buffer` that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:
+Last but not least, we will need to overcome [@ton/ton](https://www.npmjs.com/package/@ton/ton) library's reliance on Nodejs `Buffer` that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:
 
 ```console
 npm install vite-plugin-node-polyfills
@@ -162,7 +162,7 @@ Create the file `src/hooks/useTonClient.ts` with the following content:
 
 ```ts
 import { getHttpEndpoint } from '@orbs-network/ton-access';
-import { TonClient } from 'ton';
+import { TonClient } from "@ton/ton";
 import { useAsyncInitialize } from './useAsyncInitialize';
 
 export function useTonClient() {
@@ -189,7 +189,7 @@ import { Address, OpenedContract } from '@ton/core';
 export function useCounterContract() {
   const client = useTonClient();
   const [val, setVal] = useState();
-  
+
   const counterContract = useAsyncInitialize(async () => {
     if (!client) return;
     const contract = new Counter(
@@ -310,7 +310,7 @@ export function useCounterContract() {
   const { sender } = useTonConnect();
 
   const sleep = (time: number) => new Promise((resolve) => setTimeout(resolve, time));
-  
+
   const counterContract = useAsyncInitialize(async () => {
     if (!client) return;
     const contract = new Counter(
@@ -390,7 +390,7 @@ Time to rebuild the web app, run in terminal:
 npm run dev
 ```
 
-Then refresh the web browser viewing the URL shown on-screen. You should see a new "Increment" link on the bottom of the screen. I'm assuming that you're still on desktop, make a note of the counter value and click the link. 
+Then refresh the web browser viewing the URL shown on-screen. You should see a new "Increment" link on the bottom of the screen. I'm assuming that you're still on desktop, make a note of the counter value and click the link.
 
 Since your mobile Tonkeeper wallet is connected, this action should reach the Tonkeeper mobile app and cause it to display a confirmation dialog. Notice that this dialog shows the gas cost of the transaction. Approve the transaction on the mobile app. Since the app and wallet are connected, your approval should reach the app and cause it to display an indication that the transaction was sent. As you recall, new transactions must wait until they're included in a block, so this should take 5-10 seconds.
 
diff --git a/docs/03-client/testnet-npmton.html b/docs/03-client/testnet-npmton.html
index 6fda009..5707c6f 100644
--- a/docs/03-client/testnet-npmton.html
+++ b/docs/03-client/testnet-npmton.html
@@ -22,7 +22,7 @@ 

Step 3: Set up the project

npm install @ton/ton @ton/core @ton/crypto
 npm install @orbs-network/ton-access
 
-

Last but not least, we will need to overcome ton library's reliance on Nodejs Buffer that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:

+

Last but not least, we will need to overcome ton library's reliance on Nodejs Buffer that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:

npm install vite-plugin-node-polyfills
 

Now modify the file vite.config.ts so it looks like this:

@@ -103,7 +103,7 @@

Step 6: Read the counter value fro

Next, we're going to create another React hook that will rely on useAsyncInitialize and will initialize an RPC client in our app. An RPC service provider similar to Infura on Ethereum will allow us to query data from the chain. These providers run TON Blockchain nodes and allow us to communicate with them over HTTP. TON Access is an awesome service that will provide us with unthrottled API access for free. It's also decentralized, which is the preferred way to access the network.

Create the file src/hooks/useTonClient.ts with the following content:

import { getHttpEndpoint } from '@orbs-network/ton-access';
-import { TonClient } from 'ton';
+import { TonClient } from "@ton/ton";
 import { useAsyncInitialize } from './useAsyncInitialize';
 
 export function useTonClient() {
diff --git a/docs/03-client/testnet-npmton.md b/docs/03-client/testnet-npmton.md
index 9b13b0b..3c21e1a 100644
--- a/docs/03-client/testnet-npmton.md
+++ b/docs/03-client/testnet-npmton.md
@@ -42,7 +42,7 @@ npm install @ton/ton @ton/core @ton/crypto
 npm install @orbs-network/ton-access
 ```
 
-Last but not least, we will need to overcome [ton](https://www.npmjs.com/package/ton) library's reliance on Nodejs `Buffer` that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:
+Last but not least, we will need to overcome [@ton/ton](https://www.npmjs.com/package/@ton/ton) library's reliance on Nodejs `Buffer` that isn't available in the browser. We can do that by installing a polyfill. Run the following in terminal:
 
 ```console
 npm install vite-plugin-node-polyfills
@@ -162,7 +162,7 @@ Create the file `src/hooks/useTonClient.ts` with the following content:
 
 ```ts
 import { getHttpEndpoint } from '@orbs-network/ton-access';
-import { TonClient } from 'ton';
+import { TonClient } from "@ton/ton";
 import { useAsyncInitialize } from './useAsyncInitialize';
 
 export function useTonClient() {
@@ -189,7 +189,7 @@ import { Address, OpenedContract } from '@ton/core';
 export function useCounterContract() {
   const client = useTonClient();
   const [val, setVal] = useState();
-  
+
   const counterContract = useAsyncInitialize(async () => {
     if (!client) return;
     const contract = new Counter(
@@ -310,7 +310,7 @@ export function useCounterContract() {
   const { sender } = useTonConnect();
 
   const sleep = (time: number) => new Promise((resolve) => setTimeout(resolve, time));
-  
+
   const counterContract = useAsyncInitialize(async () => {
     if (!client) return;
     const contract = new Counter(
@@ -390,7 +390,7 @@ Time to rebuild the web app, run in terminal:
 npm run dev
 ```
 
-Then refresh the web browser viewing the URL shown on-screen. You should see a new "Increment" link on the bottom of the screen. I'm assuming that you're still on desktop, make a note of the counter value and click the link. 
+Then refresh the web browser viewing the URL shown on-screen. You should see a new "Increment" link on the bottom of the screen. I'm assuming that you're still on desktop, make a note of the counter value and click the link.
 
 Since your mobile Tonkeeper wallet is connected, this action should reach the Tonkeeper mobile app and cause it to display a confirmation dialog. Notice that this dialog shows the gas cost of the transaction. Approve the transaction on the mobile app. Since the app and wallet are connected, your approval should reach the app and cause it to display an indication that the transaction was sent. As you recall, new transactions must wait until they're included in a block, so this should take 5-10 seconds.