Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftAdviser committed Aug 23, 2023
2 parents ee4a4b7 + 71c3480 commit 239ea4f
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 59 deletions.
10 changes: 5 additions & 5 deletions docs/develop/dapps/ton-connect/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand All @@ -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)
Expand Down Expand Up @@ -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_)
2 changes: 1 addition & 1 deletion docs/develop/dapps/ton-connect/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/develop/dapps/ton-connect/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|
Expand Down
122 changes: 121 additions & 1 deletion docs/develop/dapps/ton-connect/message-builders.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1061,6 +1061,126 @@ 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.
<details>
<summary>Example of creating NFT Sale Body</summary>
```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
```
</details>
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
),
]
}
```
### 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)
Expand Down
2 changes: 1 addition & 1 deletion docs/develop/dapps/ton-connect/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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.
Expand Down
12 changes: 6 additions & 6 deletions docs/develop/dapps/ton-connect/protocol/requests-responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -292,8 +292,8 @@ interface SendTransactionRequest {
Where `<transaction-payload>` 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 `<wc>:<hex>` 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 `<wc>:<hex>` 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:
Expand Down Expand Up @@ -377,7 +377,7 @@ Where `<sign-data-payload>` 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)`
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions docs/develop/dapps/ton-connect/protocol/wallet-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand Down
Loading

0 comments on commit 239ea4f

Please sign in to comment.