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 Oct 16, 2023
2 parents 3f59ae2 + 28c1f87 commit 335931c
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 5 deletions.
84 changes: 84 additions & 0 deletions docs/develop/dapps/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,90 @@ print(address.to_str(is_user_friendly=True, is_bounceable=False, is_url_safe=Tru
</TabItem>
</Tabs>

### How to send standard TON transfer message.

To send a standard TON transfer message, first you need to open your wallet contract, after that, get your wallet seqno. And only after that can you send your TON transfer. Note that if you are using a non-V4 version of the wallet, you will need to rename WalletContractV4 to WalletContract{your wallet version}, for example, WalletContractV3R2.

```js
import { TonClient, WalletContractV4, internal } from "@ton/ton";
import { mnemonicNew, mnemonicToPrivateKey } from "@ton/crypto";

const client = new TonClient({
endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
});

// Convert mnemonics to private key
let mnemonics = "word1 word2 ...".split(" ");
let keyPair = await mnemonicToPrivateKey(mnemonics);

// Create wallet contract
let workchain = 0; // Usually you need a workchain 0
let wallet = WalletContractV4.create({ workchain, publicKey: keyPair.publicKey });
let contract = client.open(wallet);

// Create a transfer
let seqno: number = await contract.getSeqno();
await contract.sendTransfer({
seqno,
secretKey: keyPair.secretKey,
messages: [internal({
value: '1',
to: 'EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N',
body: 'Example transfer body',
})]
});
```

### How to calculate user's Jetton wallet address.

To calculate the user's jetton wallet address, we need to call the "get_wallet_address" get-method of the jetton master contract with user address actually. For this task we can easily use getWalletAddress method from JettonMaster or call master contract by ourselves.

<Tabs groupId="code-examples">
<TabItem value="user-jetton-wallet-method-js" label="Use getWalletAddress method">

```js
const { Address, beginCell } = require("@ton/core")
const { TonClient, JettonMaster } = require("@ton/ton")

const client = new TonClient({
endpoint: 'https://toncenter.com/api/v2/jsonRPC',
});

const jettonMasterAddress = Address.parse('...') // for example EQBlqsm144Dq6SjbPI4jjZvA1hqTIP3CvHovbIfW_t-SCALE
const userAddress = Address.parse('...')

const jettonMaster = client.open(JettonMaster.create(jettonMasterAddress))
console.log(await jettonMaster.getWalletAddress(userAddress))
```
</TabItem>

<TabItem value="user-jetton-wallet-get-method-js" label="Call get-method by ourselves">

```js
const { Address, beginCell } = require("@ton/core")
const { TonClient } = require("@ton/ton")

async function getUserWalletAddress(userAddress, jettonMasterAddress) {
const client = new TonClient({
endpoint: 'https://toncenter.com/api/v2/jsonRPC',
});
const userAddressCell = beginCell().storeAddress(userAddress).endCell()

const response = await client.runMethod(jettonMasterAddress, "get_wallet_address", [{type: "slice", cell: userAddressCell}])
return response.stack.readAddress()
}
const jettonMasterAddress = Address.parse('...') // for example EQBlqsm144Dq6SjbPI4jjZvA1hqTIP3CvHovbIfW_t-SCALE
const userAddress = Address.parse('...')

getUserWalletAddress(userAddress, jettonMasterAddress)
.then((userJettonWalletAddress) => {
console.log(userJettonWalletAddress)
}
)
```
</TabItem>
</Tabs>

### How to construct a message for a jetton transfer with a comment?

To understand how to construct a message for token transfer, we use [TEP-74](https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md#1-transfer), which describes the token standard. It's important to note that each token can have its own `decimals`, which defaults to `9`. So, in the example below, we multiply the quantity by 10^9. If decimals were different, you would **need to multiply by a different value**.
Expand Down
8 changes: 8 additions & 0 deletions docs/develop/dapps/telegram-apps/step-by-step-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ Telegram Mini Apps are web applications that run inside the Telegram messenger.
```html
<script src="https://telegram.org/js/telegram-web-app.js"></script>
```
:::tip
It's preferable to switch off cache in the HTML. To ensure your cache switched off, specify headers in your request according the following:

```curl
Cache-Control: no-store, must-revalidate
Pragma: no-cache
Expires: 0
```
:::

2. Once the script is connected, a **[window.Telegram.WebApp](https://core.telegram.org/bots/webapps#initializing-web-apps)** object become available. You can read more about creating Mini App utilising [`telegram-web-app.js`](https://docs.ton.org/develop/dapps/telegram-apps/app-examples#basic-twa-example) here.

Expand Down
12 changes: 7 additions & 5 deletions docs/develop/dapps/telegram-apps/tips-and-tricks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
# Tips and Tricks


:::danger
Page is under development.
:::


On this page, you'll find a list of frequently asked questions related to issues in TMA.

### How to solve the cache overflow issue in TMA?
Expand All @@ -29,3 +24,10 @@ Expires: 0
```
:::


### What is suggested IDE for development TMA?

The process of development in Google Chrome more convenient because of the familiar dev tools.

You can retrieve the launch parameters of the mini-app and open this link in Chrome. For our case, the easiest way is to retrieve the launch parameters from the web version of Telegram: [https://web.telegram.org/](https://web.telegram.org/)

0 comments on commit 335931c

Please sign in to comment.