From 4f3295444a7037166fb96f52eaad9ba8d5cb2fd4 Mon Sep 17 00:00:00 2001 From: AlexG <39581753+Reveloper@users.noreply.github.com> Date: Sat, 19 Aug 2023 20:22:20 +0300 Subject: [PATCH 1/7] examples_update added nft sale example for Python --- .../dapps/ton-connect/message-builders.mdx | 97 +++++++++++++++++++ docs/develop/smart-contracts/examples.md | 5 + 2 files changed, 102 insertions(+) diff --git a/docs/develop/dapps/ton-connect/message-builders.mdx b/docs/develop/dapps/ton-connect/message-builders.mdx index 2308ead615..baf9ae1947 100644 --- a/docs/develop/dapps/ton-connect/message-builders.mdx +++ b/docs/develop/dapps/ton-connect/message-builders.mdx @@ -1061,6 +1061,103 @@ transaction = { ``` +### NFT Sale (GetGems) + +
+Example of creating NFT Sale Body + +```python + import time +from base64 import urlsafe_b64encode + +from pytoniq_core.boc import Cell, begin_cell, Address +from pytoniq_core.tlb import StateInit + + +def get_sale_body(wallet_address: str, royalty_address: str, nft_address: str, price: int, amount: int): + + # contract code + nft_sale_code_cell = Cell.one_from_boc('te6cckECCwEAArkAART/APSkE/S88sgLAQIBIAIDAgFIBAUAfvIw7UTQ0wDTH/pA+kD6QPoA1NMAMMABjh34AHAHyMsAFssfUATPFljPFgHPFgH6AszLAMntVOBfB4IA//7y8AICzQYHAFegOFnaiaGmAaY/9IH0gfSB9AGppgBgYaH0gfQB9IH0AGEEIIySsKAVgAKrAQH30A6GmBgLjYSS+CcH0gGHaiaGmAaY/9IH0gfSB9AGppgBgYOCmE44BgAEqYhOmPhW8Q4YBKGATpn8cIxbMbC3MbK2QV44LJOZlvKAVxFWAAyS+G8BJrpOEBFcCBFd0VYACRWdjYKdxjgthOjq+G6hhoaYPqGAD9gHAU4ADAgB92YIQO5rKAFJgoFIwvvLhwiTQ+kD6APpA+gAwU5KhIaFQh6EWoFKQcIAQyMsFUAPPFgH6AstqyXH7ACXCACXXScICsI4XUEVwgBDIywVQA88WAfoCy2rJcfsAECOSNDTiWnCAEMjLBVADzxYB+gLLaslx+wBwIIIQX8w9FIKAejy0ZSzjkIxMzk5U1LHBZJfCeBRUccF8uH0ghAFE42RFrry4fUD+kAwRlAQNFlwB8jLABbLH1AEzxZYzxYBzxYB+gLMywDJ7VTgMDcowAPjAijAAJw2NxA4R2UUQzBw8AXgCMACmFVEECQQI/AF4F8KhA/y8AkA1Dg5ghA7msoAGL7y4clTRscFUVLHBRWx8uHKcCCCEF/MPRQhgBDIywUozxYh+gLLassfFcs/J88WJ88WFMoAI/oCE8oAyYMG+wBxUGZFFQRwB8jLABbLH1AEzxZYzxYBzxYB+gLMywDJ7VQAlsjLHxPLPyPPFlADzxbKAIIJycOA+gLKAMlxgBjIywUmzxZw+gLLaszJgwb7AHFVUHAHyMsAFssfUATPFljPFgHPFgH6AszLAMntVNZeZYk=') + + # fees cell + + marketplace_address = Address('EQBYTuYbLf8INxFtD8tQeNk5ZLy-nAX9ahQbG_yl1qQ-GEMS') + marketplace_fee_address = Address('EQCjk1hh952vWaE9bRguFkAhDAL5jj3xj9p0uPWrFBq_GEMS') + destination_address = Address('EQAIFunALREOeQ99syMbO6sSzM_Fa1RsPD5TBoS0qVeKQ-AR') + + wallet_address = Address(wallet_address) + royalty_address = Address(royalty_address) + nft_address = Address(nft_address) + + marketplace_fee = int(price * 5 / 100) # 5% + royalty_fee = int(price * 5 / 100) # 5% + + fees_data_cell = (begin_cell() + .store_address(marketplace_fee_address) + .store_coins(marketplace_fee) + .store_address(royalty_address) + .store_coins(royalty_fee) + .end_cell()) + + + sale_data_cell = (begin_cell() + .store_bit_int(0) + .store_uint(int(time.time()), 32) + .store_address(marketplace_address) + .store_address(nft_address) + .store_address(wallet_address) + .store_coins(price) + .store_ref(fees_data_cell) + .store_bit_int(0) + .end_cell()) + + state_init_cell = StateInit(code=nft_sale_code_cell, data=sale_data_cell).serialize() + + sale_body = (begin_cell() + .store_uint(1, 32) + .store_uint(0, 64) + .end_cell()) + + transfer_nft_body = (begin_cell() + .store_uint(0x5fcc3d14, 32) + .store_uint(0, 64) + .store_address(destination_address) + .store_address(wallet_address) + .store_bit_int(0) + .store_coins(int(1 * 10**9)) + .store_bit_int(0) + .store_uint(0x0fe0ede, 31) + .store_ref(state_init_cell) + .store_ref(sale_body) + .end_cell()) + + data = { + 'address': nft_address.to_str(), + 'amount': str(amount), + 'payload': urlsafe_b64encode(transfer_nft_body.to_boc()).decode() + } + + return data +``` + +
+ +The final transaction body: + +```python +transaction = { + 'valid_until': int(time.time() + 3600), + 'messages': [ + get_nft_transfer_message( + nft_address='EQDrA-3zsJXTfGo_Vdzg8d07Da4vSdHZllc6W9qvoNoMstF-', + recipient_address='0:0000000000000000000000000000000000000000000000000000000000000000', + transfer_fee=int(0.07 * 10**9), + response_address=wallet_address + ), + ] +} +``` + ## Authors - JavaScript examples provided by [@aSpite](https://t.me/aspite) - Python examples provided by [@yunwine](https://t.me/yungwine) diff --git a/docs/develop/smart-contracts/examples.md b/docs/develop/smart-contracts/examples.md index aeb6f3e31c..59acd7ac0b 100644 --- a/docs/develop/smart-contracts/examples.md +++ b/docs/develop/smart-contracts/examples.md @@ -80,6 +80,11 @@ Make sure you have thoroughly tested contracts before using them in a production * https://github.com/shuva10v/func-contest3-solutions * https://github.com/crazyministr/TonContest-FunC/tree/master/func-contest3 +#### TON Smart Challenge 4 + +* https://github.com/akifoq/tsc4 +* https://github.com/Gusarich/tsc4 +* https://github.com/Skydev0h/tsc4 ## Fift Smart Contracts From d7b44db016b85935c3b899cc6a966b354c9bc63c Mon Sep 17 00:00:00 2001 From: AlexG <39581753+Reveloper@users.noreply.github.com> Date: Sat, 19 Aug 2023 20:52:32 +0300 Subject: [PATCH 2/7] added_solutions_func --- docs/develop/smart-contracts/examples.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/develop/smart-contracts/examples.md b/docs/develop/smart-contracts/examples.md index 59acd7ac0b..e0495b4167 100644 --- a/docs/develop/smart-contracts/examples.md +++ b/docs/develop/smart-contracts/examples.md @@ -85,6 +85,8 @@ Make sure you have thoroughly tested contracts before using them in a production * https://github.com/akifoq/tsc4 * https://github.com/Gusarich/tsc4 * https://github.com/Skydev0h/tsc4 +* https://github.com/aSpite/tsc4-contracts (FunC solution) +* [https://github.com/ProgramCrafter/tsc4](https://github.com/ProgramCrafter/tsc4/tree/c1616e12d1b449b01fdcb787a3aa8442e671371e/contracts) (FunC solution) ## Fift Smart Contracts From 79d09ede1b0b036b0bd561912a67286aec05bd28 Mon Sep 17 00:00:00 2001 From: AlexG <39581753+Reveloper@users.noreply.github.com> Date: Tue, 22 Aug 2023 08:42:32 +0300 Subject: [PATCH 3/7] examples_list_tsc4_added --- docs/develop/func/overview.md | 5 +++++ docs/develop/smart-contracts/examples.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/develop/func/overview.md b/docs/develop/func/overview.md index 3be42d10b3..0bc3f22e2c 100644 --- a/docs/develop/func/overview.md +++ b/docs/develop/func/overview.md @@ -69,6 +69,11 @@ Other materials gracefully provided by the experts from the community: Participating in [contests](https://t.me/toncontests) is a great way to learn FunC. You can also study previous competitions for learning purposes: +* TON Smart Challenge #4 (best for getting started): + [Contest Page](https://ton.org/ton-smart-challenge-4), + [Tasks](https://github.com/ton-community/tsc4), + [Solutions](/develop/smart-contracts/examples#ton-smart-challenge-4), + * TON Smart Challenge #2 (good for getting started): [Contest Page](https://ton.org/ton-smart-challenge-2), [Tasks](https://github.com/ton-blockchain/func-contest2), diff --git a/docs/develop/smart-contracts/examples.md b/docs/develop/smart-contracts/examples.md index e0495b4167..122c90d75e 100644 --- a/docs/develop/smart-contracts/examples.md +++ b/docs/develop/smart-contracts/examples.md @@ -82,7 +82,7 @@ Make sure you have thoroughly tested contracts before using them in a production #### TON Smart Challenge 4 -* https://github.com/akifoq/tsc4 +* https://github.com/akifoq/tsc4 (TOP optimized) * https://github.com/Gusarich/tsc4 * https://github.com/Skydev0h/tsc4 * https://github.com/aSpite/tsc4-contracts (FunC solution) From 46d39c6349e8087c906db33d31f127c15ef5a854 Mon Sep 17 00:00:00 2001 From: AlexG <39581753+Reveloper@users.noreply.github.com> Date: Tue, 22 Aug 2023 12:00:33 +0300 Subject: [PATCH 4/7] python_example_update --- .../dapps/ton-connect/message-builders.mdx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/develop/dapps/ton-connect/message-builders.mdx b/docs/develop/dapps/ton-connect/message-builders.mdx index baf9ae1947..2eded502dc 100644 --- a/docs/develop/dapps/ton-connect/message-builders.mdx +++ b/docs/develop/dapps/ton-connect/message-builders.mdx @@ -1063,6 +1063,12 @@ transaction = { ### NFT Sale (GetGems) + +Here is an example of preparing message and transaction for sale on GetGems marketplace, according to contract [nft-fixprice-sale-v3r2](https://github.com/getgems-io/nft-contracts/blob/main/packages/contracts/sources/nft-fixprice-sale-v3r2.fc). + +To place NFT on GetGems Sale Contract, we should prepare special message body `transferNftBody` that will be transfer NFT to special NFT Sale Contract. + +
Example of creating NFT Sale Body @@ -1158,6 +1164,23 @@ transaction = { } ``` +### NFT Buy (GetGems) + +The process of buy NFT for [nft-fixprice-sale-v3r2](https://github.com/getgems-io/nft-contracts/blob/main/packages/contracts/sources/nft-fixprice-sale-v3r2.fc) sale contract could be carry out with regular transfer without payload, the only important thing is accurate TON amount, that calculates as follows: +`buyAmount = Nftprice TON + 1.0 TON`. + + +```python +transaction = { + 'valid_until': int(time.time() + 3600), + 'messages': [ + { + 'address': nft_address, + 'amount': buyAmount, + ] +} +``` + ## Authors - JavaScript examples provided by [@aSpite](https://t.me/aspite) - Python examples provided by [@yunwine](https://t.me/yungwine) From 795317e9cc325dcad8becc841def7d40c636c27c Mon Sep 17 00:00:00 2001 From: AlexG <39581753+Reveloper@users.noreply.github.com> Date: Wed, 23 Aug 2023 10:43:43 +0300 Subject: [PATCH 5/7] sign_update --- .../dapps/ton-connect/message-builders.mdx | 2 +- docs/develop/dapps/ton-connect/sign.mdx | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/develop/dapps/ton-connect/message-builders.mdx b/docs/develop/dapps/ton-connect/message-builders.mdx index 2eded502dc..4ac022849a 100644 --- a/docs/develop/dapps/ton-connect/message-builders.mdx +++ b/docs/develop/dapps/ton-connect/message-builders.mdx @@ -615,7 +615,7 @@ To place NFT on GetGems Sale Contract, we should prepare special message body `t const transferNftBody = beginCell() .storeUint(0x5fcc3d14, 32) // Opcode for NFT transfer .storeUint(0, 64) // query_id - .storeAddress(destinationAddress) // new_owner + .storeAddress(destinationAddress) // new_owner - GetGems sale contracts deployer, should never change for this operation .storeAddress(walletAddress) // response_destination for excesses .storeBit(0) // we do not have custom_payload .storeCoins(toNano("1")) // forward_amount diff --git a/docs/develop/dapps/ton-connect/sign.mdx b/docs/develop/dapps/ton-connect/sign.mdx index 8cb59d23cb..86953fcc6e 100644 --- a/docs/develop/dapps/ton-connect/sign.mdx +++ b/docs/develop/dapps/ton-connect/sign.mdx @@ -3,12 +3,12 @@ import ThemedImage from '@theme/ThemedImage'; # Signing and Verification -:::warning -The page is under development. +:::tip +Please, note, that signing is not require for all dApps. It will be useful, if you want to verify your user for providing to him his personal information from back end. ::: -Signature in works in TON Connect with a special `TonProof` entity, which implemented inside connector. +Signature works in TON Connect with a special `TonProof` entity, which implemented inside connector. ```js type TonProofItemReply = TonProofItemReplySuccess | TonProofItemReplyError; @@ -44,6 +44,15 @@ type TonProofItemReplySuccess = { />

+## How to Check TON Proof in dApp with API + +1. Try to obtain public key via get_public_key get method on smart contract deployed at Address +2. If the smart contract is not deployed (user just created new wallet locally in the wallet app), check the following: + * Parse walletStateInit via TonAddressItemReply.walletStateInit + * Retrieve `{public_key, address}` from `walletStateInit` with [TON API](https://tonapi.io/) method https://tonapi.io/v2/tonconnect/stateinit + * Check that address extracted from walletStateInit corresponds to wallet's address declared by user. +3. Check timestamp, domain, signature (examples [GO]((https://github.com/ton-connect/demo-dapp-backend/blob/master/proof.go), [TS](https://gist.github.com/TrueCarry/cac00bfae051f7028085aa018c2a05c6), [Python]((https://github.com/XaBbl4/pytonconnect/blob/main/examples/check_proof.py))) + ## How to Check TON Proof on Server Side Obtain from the frontend the following data: wallet address, domain, timestamp, walletStateInit, signature @@ -195,7 +204,7 @@ The signature must be verified by public key: * [GO demo app](https://github.com/ton-connect/demo-dapp-backend/blob/master/proof.go) * [TS example](https://gist.github.com/TrueCarry/cac00bfae051f7028085aa018c2a05c6) -* [Python example](https://github.com/disintar/ton-connect-python-proof/blob/master/check_proof.ipynb?short_path=8776c84) +* [Python example](https://github.com/XaBbl4/pytonconnect/blob/main/examples/check_proof.py) ## See Also From 33c3843e9bb2bdd4edb79696d107e129d0d1fdfe Mon Sep 17 00:00:00 2001 From: AlexG <39581753+Reveloper@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:07:39 +0300 Subject: [PATCH 6/7] sign_upd_2 --- docs/develop/dapps/ton-connect/sign.mdx | 40 +++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/develop/dapps/ton-connect/sign.mdx b/docs/develop/dapps/ton-connect/sign.mdx index 86953fcc6e..3b72b2d114 100644 --- a/docs/develop/dapps/ton-connect/sign.mdx +++ b/docs/develop/dapps/ton-connect/sign.mdx @@ -2,13 +2,31 @@ import ThemedImage from '@theme/ThemedImage'; # Signing and Verification +## ton_proof Use Case -:::tip Please, note, that signing is not require for all dApps. It will be useful, if you want to verify your user for providing to him his personal information from back end. -::: +This is necessary for authorization on the backend (to prove that the user really has the declared address) -Signature works in TON Connect with a special `TonProof` entity, which implemented inside connector. +## How ton_proof Works? + +- Send dApp id to client. Typically, dApp id nested in the QR code. +- Retrieve signed transaction with ton_proof entity +- Verify ton_proof on the backend side + +

+ +

+ +## ton_proof structure + +ton_proof works in TON Connect with a special `TonProof` entity, which implemented inside connector. ```js type TonProofItemReply = TonProofItemReplySuccess | TonProofItemReplyError; @@ -28,22 +46,6 @@ type TonProofItemReplySuccess = { ``` -## How to use TON Proof (High-Level) - -- Send dApp id to client. Typically, dApp id nested in the QR code. -- Retrieve signed transaction with ton_proof entity -- Verify ton_proof on the backend side - -

- -

- ## How to Check TON Proof in dApp with API 1. Try to obtain public key via get_public_key get method on smart contract deployed at Address From 11c8f4153d22e91164c3a0b012e3d18c083e09a9 Mon Sep 17 00:00:00 2001 From: AlexG <39581753+Reveloper@users.noreply.github.com> Date: Wed, 23 Aug 2023 16:41:32 +0300 Subject: [PATCH 7/7] DApp_rename_update --- docs/develop/dapps/ton-connect/developers.md | 10 ++++---- docs/develop/dapps/ton-connect/integration.md | 2 +- docs/develop/dapps/ton-connect/manifest.md | 2 +- docs/develop/dapps/ton-connect/overview.mdx | 2 +- .../protocol/requests-responses.md | 12 +++++----- .../ton-connect/protocol/wallet-guidelines.md | 18 +++++++------- docs/develop/dapps/ton-connect/react.mdx | 4 ++-- docs/develop/dapps/ton-connect/sign.mdx | 24 +++++++++---------- .../dapps/ton-connect/tg-bot-integration.md | 2 +- .../develop/dapps/ton-connect/transactions.md | 2 +- .../dapps/tutorials/simple-zk-on-ton.md | 2 +- docs/develop/overview.mdx | 2 +- docs/participate/wallets/contracts.md | 2 +- sidebars.js | 2 +- .../ton-connect/ton_proof_scheme-dark.svg | 8 +++---- .../img/docs/ton-connect/ton_proof_scheme.svg | 8 +++---- 16 files changed, 51 insertions(+), 51 deletions(-) diff --git a/docs/develop/dapps/ton-connect/developers.md b/docs/develop/dapps/ton-connect/developers.md index d8d23f7d63..a02de08dac 100644 --- a/docs/develop/dapps/ton-connect/developers.md +++ b/docs/develop/dapps/ton-connect/developers.md @@ -19,7 +19,7 @@ This page contents the list of useful libraries for TON Connect. TonConnect UI React is a React UI kit for TonConnect SDK. Use it to connect your app to TON wallets via TonConnect protocol in React apps. -* Example of a DApp with `@tonconnect/ui-react`: [GitHub](https://github.com/ton-connect/demo-dapp-with-react-ui) +* Example of a DAppwith `@tonconnect/ui-react`: [GitHub](https://github.com/ton-connect/demo-dapp-with-react-ui) * Example of deployed `demo-dapp-with-react-ui`: [GitHub](https://ton-connect.github.io/demo-dapp-with-react-ui/) ```bash @@ -56,8 +56,8 @@ The TON Connect User Interface (UI) is a framework that allows developers to imp TON Connect can easily be integrated with apps using simple UI elements such as the "connect wallet button", "select wallet dialog" and confirmation modals. Here are three main examples of how TON Connect improves UX in apps: -* Example of app functionality in the dApp browser: [GitHub](https://ton-connect.github.io/demo-dapp/) -* Example of a backend partition of the dApp above: [GitHub](https://github.com/ton-connect/demo-dapp-backend) +* Example of app functionality in the DAppbrowser: [GitHub](https://ton-connect.github.io/demo-dapp/) +* Example of a backend partition of the DAppabove: [GitHub](https://github.com/ton-connect/demo-dapp-backend) * Bridge server using Go: [GitHub](https://github.com/ton-connect/bridge) @@ -73,7 +73,7 @@ The most low-level of the three frameworks that helps developers integrate TON C ### TON Connect protocol models -This package contains protocol requests, protocol responses, event models and encoding and decoding functions. It can be used to integrate TON Connect to wallet apps written in TypeScript. In order to integrate TON Connect into a dApp the [@tonconnect/sdk](https://www.npmjs.com/package/@tonconnect/sdk) should be used. +This package contains protocol requests, protocol responses, event models and encoding and decoding functions. It can be used to integrate TON Connect to wallet apps written in TypeScript. In order to integrate TON Connect into a DAppthe [@tonconnect/sdk](https://www.npmjs.com/package/@tonconnect/sdk) should be used. - [GitHub](https://github.com/ton-connect/sdk/tree/main/packages/protocol) - [NPM](https://www.npmjs.com/package/@tonconnect/protocol) @@ -116,7 +116,7 @@ If you experience any additional issues, or would like to present a proposal on ## See Also * [Step by step guide for building your first web client](https://ton-community.github.io/tutorials/03-client/) -* [[YouTube] TON Smart Contracts | 10 | Telegram dapp [EN]](https://www.youtube.com/watch?v=D6t3eZPdgAU&t=254s&ab_channel=AlefmanVladimir%5BEN%5D) +* [[YouTube] TON Smart Contracts | 10 | Telegram DApp[EN]](https://www.youtube.com/watch?v=D6t3eZPdgAU&t=254s&ab_channel=AlefmanVladimir%5BEN%5D) * [Ton Connect Getting started](https://github.com/ton-connect/sdk/tree/main/packages/sdk) * [Integration Manual](/develop/dapps/ton-connect/integration) * [[YouTube] TON Dev Study TON Connect Protocol [RU]](https://www.youtube.com/playlist?list=PLyDBPwv9EPsCJ226xS5_dKmXXxWx1CKz_) diff --git a/docs/develop/dapps/ton-connect/integration.md b/docs/develop/dapps/ton-connect/integration.md index c1309a8182..495f174094 100644 --- a/docs/develop/dapps/ton-connect/integration.md +++ b/docs/develop/dapps/ton-connect/integration.md @@ -74,7 +74,7 @@ According to TON Connect 2.0 specifications, wallet app information always makes bridgeUrl?: string; jsBridgeKey?: string; injected?: boolean; // true if this wallet is injected to the webpage - embedded?: boolean; // true if the dapp is opened inside this wallet's browser + embedded?: boolean; // true if the DAppis opened inside this wallet's browser } ``` diff --git a/docs/develop/dapps/ton-connect/manifest.md b/docs/develop/dapps/ton-connect/manifest.md index 68c1bcb749..d0598c7669 100644 --- a/docs/develop/dapps/ton-connect/manifest.md +++ b/docs/develop/dapps/ton-connect/manifest.md @@ -32,7 +32,7 @@ You can find an example of the manifest below: ## Fields description |Field|Requirement|Description| |---|---|---| -|`url` |required| app URL. Will be used as the dapp identifier. Will be used to open the dapp after click to its icon in the wallet. It is recommended to pass url without closing slash, e.g. 'https://mydapp.com' instead of 'https://mydapp.com/'.| +|`url` |required| app URL. Will be used as the DAppidentifier. Will be used to open the DAppafter click to its icon in the wallet. It is recommended to pass url without closing slash, e.g. 'https://mydapp.com' instead of 'https://mydapp.com/'.| | `name`|required| app name. Might be simple, will not be used as identifier.| | `iconUrl`| required | Url to the app icon. Must be PNG, ICO, ... format. SVG icons are not supported. Perfectly pass url to a 180x180px PNG icon.| | `termsOfUseUrl` |optional| url to the Terms Of Use document. Optional for usual apps, but required for the apps which is placed in the Tonkeeper recommended apps list.| diff --git a/docs/develop/dapps/ton-connect/overview.mdx b/docs/develop/dapps/ton-connect/overview.mdx index 0e7232bc32..220c039770 100644 --- a/docs/develop/dapps/ton-connect/overview.mdx +++ b/docs/develop/dapps/ton-connect/overview.mdx @@ -20,7 +20,7 @@ If you are a wallet developer, please read how to [integrate TON Connect into yo ## Use Cases For Your DApp -Explore these deliverables that the TON Ecosystem provides for superior DApp integration. +Explore these deliverables that the TON Ecosystem provides for superior DAppintegration. - **Traffic**. Drive additional user visits via crypto wallets that support TON Connect. - **Authenticity**. Leverage TON user's wallets as ready-made accounts, removing the need for additional authentication steps and thus, boosting user experience. diff --git a/docs/develop/dapps/ton-connect/protocol/requests-responses.md b/docs/develop/dapps/ton-connect/protocol/requests-responses.md index a10a891518..e4ac685017 100644 --- a/docs/develop/dapps/ton-connect/protocol/requests-responses.md +++ b/docs/develop/dapps/ton-connect/protocol/requests-responses.md @@ -25,7 +25,7 @@ Best practice is to place the manifest in the root of your app, e.g. `https://my Make sure that manifest is available to GET by its URL. #### Fields description -- `url` -- app URL. Will be used as the dapp identifier. Will be used to open the dapp after click to its icon in the wallet. It is recommended to pass url without closing slash, e.g. 'https://mydapp.com' instead of 'https://mydapp.com/'. +- `url` -- app URL. Will be used as the DAppidentifier. Will be used to open the DAppafter click to its icon in the wallet. It is recommended to pass url without closing slash, e.g. 'https://mydapp.com' instead of 'https://mydapp.com/'. - `name` -- app name. Might be simple, will not be used as identifier. - `iconUrl` -- Url to the app icon. Must be PNG, ICO, ... format. SVG icons are not supported. Perfectly pass url to a 180x180px PNG icon. - `termsOfUseUrl` -- (optional) url to the Terms Of Use document. Optional for usual apps, but required for the apps which is placed in the Tonkeeper recommended apps list. @@ -273,7 +273,7 @@ type WalletEventName = 'connect' | 'connect_error' | 'disconnect'; Wallet must increase `id` while generating a new event. (Every next event must have `id` > previous event `id`) -DApp doesn't accept any event with an id that does not greater the last processed event id of that session. +DAppdoesn't accept any event with an id that does not greater the last processed event id of that session. ### Methods @@ -292,8 +292,8 @@ interface SendTransactionRequest { Where `` is JSON with following properties: * `valid_until` (integer, optional): unix timestamp. after th moment transaction will be invalid. -* `network` (NETWORK, optional): The network (mainnet or testnet) where DApp intends to send the transaction. If not set, the transaction is sent to the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction. -* `from` (string in `:` format, optional) - The sender address from which DApp intends to send the transaction. If not set, wallet allows user to select the sender's address at the moment of transaction approval. If `from` parameter is set, the wallet should DO NOT ALLOW user to select the sender's address; If sending from the specified address is impossible, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction. +* `network` (NETWORK, optional): The network (mainnet or testnet) where DAppintends to send the transaction. If not set, the transaction is sent to the network currently set in the wallet, but this is not safe and DAppshould always strive to set the network. If the `network` parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction. +* `from` (string in `:` format, optional) - The sender address from which DAppintends to send the transaction. If not set, wallet allows user to select the sender's address at the moment of transaction approval. If `from` parameter is set, the wallet should DO NOT ALLOW user to select the sender's address; If sending from the specified address is impossible, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction. * `messages` (array of messages): 1-4 outgoing messages from the wallet contract to other accounts. All messages are sent out in order, however **the wallet cannot guarantee that messages will be delivered and executed in same order**. Message structure: @@ -377,7 +377,7 @@ Where `` is JSON with following properties: * `schema_crc` (integer): indicates the layout of payload cell that in turn defines domain separation. * `cell` (string, base64 encoded Cell): contains arbitrary data per its TL-B definition. -* `publicKey` (HEX string without 0x, optional): The public key of key pair from which DApp intends to sign the data. If not set, the wallet is not limited in what keypair to sign. If `publicKey` parameter is set, the wallet SHOULD to sign by keypair corresponding this public key; If sign by this specified keypair is impossible, the wallet should show an alert and DO NOT ALLOW TO SIGN this data. +* `publicKey` (HEX string without 0x, optional): The public key of key pair from which DAppintends to sign the data. If not set, the wallet is not limited in what keypair to sign. If `publicKey` parameter is set, the wallet SHOULD to sign by keypair corresponding this public key; If sign by this specified keypair is impossible, the wallet should show an alert and DO NOT ALLOW TO SIGN this data. The signature will be computed in the following way: `ed25519(uint32be(schema_crc) ++ uint64be(timestamp) ++ cell_hash(X), privkey)` @@ -418,7 +418,7 @@ interface SignDataResponseError { #### Disconnect operation -When user disconnects the wallet in the dApp, dApp should inform the wallet to help the wallet save resources and delete unnecessary session. +When user disconnects the wallet in the dApp, DAppshould inform the wallet to help the wallet save resources and delete unnecessary session. Allows the wallet to update its interface to the disconnected state. ```tsx diff --git a/docs/develop/dapps/ton-connect/protocol/wallet-guidelines.md b/docs/develop/dapps/ton-connect/protocol/wallet-guidelines.md index 02b5bf7847..b7f6a43eed 100644 --- a/docs/develop/dapps/ton-connect/protocol/wallet-guidelines.md +++ b/docs/develop/dapps/ton-connect/protocol/wallet-guidelines.md @@ -11,16 +11,16 @@ ### Hide the Testnet from ordinary users. Testnet is used exclusively by developers. Ordinary users should not see the Testnet. -This means that switching to Testnet should not be readily available and users SHOULD NOT be prompted to switch wallet to Testnet even if dapp is in Testnet. +This means that switching to Testnet should not be readily available and users SHOULD NOT be prompted to switch wallet to Testnet even if DAppis in Testnet. Users switch to Testnet, don't understand this action, can't switch back to Mainnet. -For these reasons, dapps do not need to switch networks in runtime, on the contrary, it is more preferable to have different instances of dapp on different domains dapp.com, Testnet.dapp.com. +For these reasons, dapps do not need to switch networks in runtime, on the contrary, it is more preferable to have different instances of DAppon different domains dapp.com, Testnet.dapp.com. For the same reason there is no `NetworkChanged` or `ChainChanged` event in the Ton Connect protocol. -### Do not send anything if the dapp is in Testnet and the wallet is in Mainnet. +### Do not send anything if the DAppis in Testnet and the wallet is in Mainnet. - It is necessary to prevent loss of funds when dapp tries to send a transaction in Testnet, and the wallet sends it in Mainnet. + It is necessary to prevent loss of funds when DApptries to send a transaction in Testnet, and the wallet sends it in Mainnet. Dapps should explicitly indicate `network` field in `SendTransaction` request. @@ -40,21 +40,21 @@ We think of a wallet as a physical wallet that can contain many "bank cards" (ac In most cases the sender address is not important to dapp, in these cases the user can select the appropriate account at the time of approving the transaction and the transaction will be sent from selected account. -In some cases, it is important for dapp to send the transaction from a specific address, in which case it explicitly specifies the `from` field in `SendTransaction` request. If `from` parameter is set, the wallet should DO NOT ALLOW user to select the sender's address; If sending from the specified address is impossible, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction. +In some cases, it is important for DAppto send the transaction from a specific address, in which case it explicitly specifies the `from` field in `SendTransaction` request. If `from` parameter is set, the wallet should DO NOT ALLOW user to select the sender's address; If sending from the specified address is impossible, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction. ### Login flow -When dapp connects the wallet, the user selects in the wallet one of their accounts that they want to log into dapp. +When DAppconnects the wallet, the user selects in the wallet one of their accounts that they want to log into dapp. -Regardless of what accounts the user uses next in the wallet, dapp works with the account he received on the connection. +Regardless of what accounts the user uses next in the wallet, DAppworks with the account he received on the connection. Just like if you logged into a web service with one of your email accounts - if you then change the email account in the email service, the web service continues to use the one he got when you logged in. For this reason, the protocol does not provide the `AccountChanged` event. -To switch account user need to disconnect (Log out) and connect (Login) again in dapp UI. +To switch account user need to disconnect (Log out) and connect (Login) again in DAppUI. -We recommend wallets provide the ability to disconnect session with a specified dapp because the dapp may have an incomplete UI. +We recommend wallets provide the ability to disconnect session with a specified DAppbecause the DAppmay have an incomplete UI. ## See Also diff --git a/docs/develop/dapps/ton-connect/react.mdx b/docs/develop/dapps/ton-connect/react.mdx index 8728da12db..bce7af49c9 100644 --- a/docs/develop/dapps/ton-connect/react.mdx +++ b/docs/develop/dapps/ton-connect/react.mdx @@ -313,8 +313,8 @@ await tonConnectUI.disconnect(); ## Examples -* Step-by-step [TON Hello World guide](https://ton-community.github.io/tutorials/03-client/) to create a simple DApp with React UI. -* [Demo dApp](https://github.com/ton-connect/demo-dapp-with-react-ui) - Example of a DApp with `@tonconnect/ui-react`. +* Step-by-step [TON Hello World guide](https://ton-community.github.io/tutorials/03-client/) to create a simple DAppwith React UI. +* [Demo dApp](https://github.com/ton-connect/demo-dapp-with-react-ui) - Example of a DAppwith `@tonconnect/ui-react`. * [ton.vote](https://github.com/orbs-network/ton-vote) - Example of React website with TON Connect implementation. diff --git a/docs/develop/dapps/ton-connect/sign.mdx b/docs/develop/dapps/ton-connect/sign.mdx index 3b72b2d114..71c048bb08 100644 --- a/docs/develop/dapps/ton-connect/sign.mdx +++ b/docs/develop/dapps/ton-connect/sign.mdx @@ -2,15 +2,14 @@ import ThemedImage from '@theme/ThemedImage'; # Signing and Verification -## ton_proof Use Case +## Use Cases -Please, note, that signing is not require for all dApps. It will be useful, if you want to verify your user for providing to him his personal information from back end. -This is necessary for authorization on the backend (to prove that the user really has the declared address) +Please note that signing is not required for all DApps. It will be useful if you want to verify a user to provide them with their personal information from the back end. This is necessary for authorization on the backend, to prove that the user truly owned the declared address. ## How ton_proof Works? -- Send dApp id to client. Typically, dApp id nested in the QR code. +- Send DAppid to client. Typically, DAppid nested in the QR code. - Retrieve signed transaction with ton_proof entity - Verify ton_proof on the backend side @@ -24,7 +23,7 @@ This is necessary for authorization on the backend (to prove that the user reall />

-## ton_proof structure +## Structure of ton_proof ton_proof works in TON Connect with a special `TonProof` entity, which implemented inside connector. @@ -46,14 +45,15 @@ type TonProofItemReplySuccess = { ``` -## How to Check TON Proof in dApp with API +## Check ton_proof with API -1. Try to obtain public key via get_public_key get method on smart contract deployed at Address -2. If the smart contract is not deployed (user just created new wallet locally in the wallet app), check the following: - * Parse walletStateInit via TonAddressItemReply.walletStateInit - * Retrieve `{public_key, address}` from `walletStateInit` with [TON API](https://tonapi.io/) method https://tonapi.io/v2/tonconnect/stateinit - * Check that address extracted from walletStateInit corresponds to wallet's address declared by user. -3. Check timestamp, domain, signature (examples [GO]((https://github.com/ton-connect/demo-dapp-backend/blob/master/proof.go), [TS](https://gist.github.com/TrueCarry/cac00bfae051f7028085aa018c2a05c6), [Python]((https://github.com/XaBbl4/pytonconnect/blob/main/examples/check_proof.py))) +1. Retrieve `TonProofItemReply` from user. +2. Try to obtain public key via get_public_key get method on smart contract deployed at `address` +3. If the smart contract has not been deployed (e.g., the user has just created a new wallet locally in the wallet app) or does not support get_public_key method(v3 contracts), follow these steps: +* a. Parse wallet's StateInit `walletStateInit = TonAddressItemReply.walletStateInit` +* b. Retrieve `{public_key, address}` from `walletStateInit` with [TON API](https://tonapi.io/) method POST /v2/tonconnect/stateinit +* Check that `address` extracted from `walletStateInit` or corresponds to wallet's `address` declared by user. +4. Verify timestamp, domain, signature with `public_key` (examples [GO](https://github.com/ton-connect/demo-dapp-backend/blob/master/proof.go), [TS](https://gist.github.com/TrueCarry/cac00bfae051f7028085aa018c2a05c6), [Python](https://github.com/XaBbl4/pytonconnect/blob/main/examples/check_proof.py)) ## How to Check TON Proof on Server Side diff --git a/docs/develop/dapps/ton-connect/tg-bot-integration.md b/docs/develop/dapps/ton-connect/tg-bot-integration.md index 747bd1385a..48cf9f88e6 100644 --- a/docs/develop/dapps/ton-connect/tg-bot-integration.md +++ b/docs/develop/dapps/ton-connect/tg-bot-integration.md @@ -95,7 +95,7 @@ Create a `tsconfig.json`: [Read more about tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) ### Add simple bot code -Create a `.env` file and add your bot token, dApp manifest and wallets list cache time to live there: +Create a `.env` file and add your bot token, DAppmanifest and wallets list cache time to live there: [See more about tonconnect-manifes.json](https://github.com/ton-connect/sdk/tree/main/packages/sdk#add-the-tonconnect-manifest) diff --git a/docs/develop/dapps/ton-connect/transactions.md b/docs/develop/dapps/ton-connect/transactions.md index fa4744ebdb..8d97fcaadb 100644 --- a/docs/develop/dapps/ton-connect/transactions.md +++ b/docs/develop/dapps/ton-connect/transactions.md @@ -3,7 +3,7 @@ TON Connect 2.0 has more powerful options than just authenticating users in the dApp: it's possible to send outgoing messages via connected wallets! You will understand: -- how to send messages from the DApp to the blockchain +- how to send messages from the DAppto the blockchain - how to send multiple messages in one transaction - how to deploy a contract using TON Connect diff --git a/docs/develop/dapps/tutorials/simple-zk-on-ton.md b/docs/develop/dapps/tutorials/simple-zk-on-ton.md index f17bc2eb28..8d6c5c3ab2 100644 --- a/docs/develop/dapps/tutorials/simple-zk-on-ton.md +++ b/docs/develop/dapps/tutorials/simple-zk-on-ton.md @@ -27,7 +27,7 @@ The verifier shows one of the pieces of paper to you (the prover) and asks you t Now if the verifier do this 10 times, and you can tell the difference every time, then the verifier will be convinced ~99.90234% (1 - (1/2)^10) that you can see colors. And if the verifier do this 30 times, then the verifier will be 99.99999990686774% (1 - (1/2)^30) convinced that you can see colors. -But this is an interactive solution, and we can't have a Dapp that ask user to send 30 transactions to prove some claim! So we need a non-interactive solution. And this is where Zk-SNARKs and STARKs come in. +But this is an interactive solution, and we can't have a DAppthat ask user to send 30 transactions to prove some claim! So we need a non-interactive solution. And this is where Zk-SNARKs and STARKs come in. We will only cover Zk-SNARK in this tutorial, but you can read more about STARKs [here](https://starkware.co/stark/) and the comparison between Zk-SNARK and STARK [here](https://blog.pantherprotocol.io/zk-snarks-vs-zk-starks-differences-in-zero-knowledge-technologies/). diff --git a/docs/develop/overview.mdx b/docs/develop/overview.mdx index 197c9568e9..9e452765ae 100644 --- a/docs/develop/overview.mdx +++ b/docs/develop/overview.mdx @@ -40,7 +40,7 @@ The following resources provide valuable information for TON smart contract deve * [Learn Smart Contracts by examples](/develop/smart-contracts/examples) (FunC, Fift) -## DApp Development +## DAppDevelopment Decentralized applications (dApps) are applications that run on a peer-to-peer network of computers rather than a single computer (TON Blockchain). They are similar to traditional web applications, but they are built on top of a blockchain network. This means that dApps are decentralized, meaning that no single entity controls them. diff --git a/docs/participate/wallets/contracts.md b/docs/participate/wallets/contracts.md index 5445e79c9f..515685d6ad 100644 --- a/docs/participate/wallets/contracts.md +++ b/docs/participate/wallets/contracts.md @@ -52,7 +52,7 @@ Wallet source code: It is the most modern wallet version at the moment. It still has all the functionality of the previous versions, but also introduces something very powerful — `plugins`. -This feature allows developers to implement complex logic that will work in tandem with a user's wallet. For example, some dApp may require a user to pay a small amount of coins every day to use some features, so the user will need to install the plugin on their wallet by signing a transaction. This plugin will send coins to the destination address every day when it will be reqested by an external message. +This feature allows developers to implement complex logic that will work in tandem with a user's wallet. For example, some DAppmay require a user to pay a small amount of coins every day to use some features, so the user will need to install the plugin on their wallet by signing a transaction. This plugin will send coins to the destination address every day when it will be reqested by an external message. This is a very customizable feature which is unique to TON Blockchain. diff --git a/sidebars.js b/sidebars.js index 04d9b9e097..11b188f50c 100644 --- a/sidebars.js +++ b/sidebars.js @@ -281,7 +281,7 @@ const sidebars = { { type: 'category', - label: 'DApp Development', + label: 'DAppDevelopment', items: [ 'develop/dapps/README', 'develop/dapps/twa', diff --git a/static/img/docs/ton-connect/ton_proof_scheme-dark.svg b/static/img/docs/ton-connect/ton_proof_scheme-dark.svg index c19a6820a7..f64169edf7 100644 --- a/static/img/docs/ton-connect/ton_proof_scheme-dark.svg +++ b/static/img/docs/ton-connect/ton_proof_scheme-dark.svg @@ -79,7 +79,7 @@ Actor lifeline - dApp frontend + DAppfrontend Sheet.39 @@ -95,7 +95,7 @@ - dApp DAppfrontend @@ -106,7 +106,7 @@ Object lifeline - dApp backend + DAppbackend Sheet.44 @@ -126,7 +126,7 @@ - dApp DAppbackend diff --git a/static/img/docs/ton-connect/ton_proof_scheme.svg b/static/img/docs/ton-connect/ton_proof_scheme.svg index c1c3d33e5a..65846690d0 100644 --- a/static/img/docs/ton-connect/ton_proof_scheme.svg +++ b/static/img/docs/ton-connect/ton_proof_scheme.svg @@ -81,7 +81,7 @@ Actor lifeline - dApp frontend + DAppfrontend Sheet.39 - dApp DAppfrontend @@ -118,7 +118,7 @@ Object lifeline - dApp backend + DAppbackend Sheet.44 - dApp DAppbackend