diff --git a/website/i18n/en.json b/website/i18n/en.json index 2ff2ed2..699d107 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -376,6 +376,10 @@ "title": "TEE Technology", "sidebar_label": "TEE Technology" }, + "tonApplications": { + "title": "TON applications", + "sidebar_label": "TON applications" + }, "tonBuild101": { "title": "Build With TON 101", "sidebar_label": "Build With TON 101" diff --git a/website/sidebars.json b/website/sidebars.json index c6d9362..5416bbd 100644 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -121,7 +121,8 @@ ], "Build With TON": [ "tonBuildOverview", - "tonBuild101" + "tonBuild101", + "tonApplications" ], "Node": [ "nodeOverview", diff --git a/website/translated_docs/zh-CN/ton-applications.md b/website/translated_docs/zh-CN/ton-applications.md new file mode 100644 index 0000000..6996593 --- /dev/null +++ b/website/translated_docs/zh-CN/ton-applications.md @@ -0,0 +1,25 @@ +--- +id: tonApplications +title: TON applications +sidebar_label: TON applications +--- + +## I. Telegram Mini Apps + +We have built a [Telegram Mini Apps](https://core.telegram.org/bots/webapps) for users to directly upload and store files to TONBags in telegram. + +1. In telegram, search and add TonBagsBot(Test) + + ![Pic](assets/build/tonbags-miniapp-addbot.png) + +2. Use '/connect' command to connect to your TON wallet + + ![Pic](assets/build/tonbags-miniapp-connect.png) + +3. Select and upload some files. Confirm the transaction on the connected TON wallet. + +4. Use '/my_files' command to launch the Mini Apps. + + ![Pic](assets/build/tonbags-miniapp-myfiles.png) + + ![Pic](assets/build/tonbags-miniapp-files.png) \ No newline at end of file diff --git a/website/translated_docs/zh-CN/ton-build-101.md b/website/translated_docs/zh-CN/ton-build-101.md index 3503b6c..3ab75cb 100644 --- a/website/translated_docs/zh-CN/ton-build-101.md +++ b/website/translated_docs/zh-CN/ton-build-101.md @@ -10,7 +10,72 @@ This article will describe how to use TON storage smart contract to place order. ## II. Storage smart contract -- Testnet storage contract address: https://testnet.tonviewer.com/kQBOOMNqG0rvNm6vFGfR4qZl48BTDw_gYefVI4DQ70t9GjhI +- Testnet storage contract address: https://testnet.tonviewer.com/EQBOOMNqG0rvNm6vFGfR4qZl48BTDw_gYefVI4DQ70t9GoPC - Mainnet storage contract address: (coming soon) -## III. Example (coming soon) +## III. SDK & Example + +Developers could use [tonbags-sdk](https://www.npmjs.com/package/@crustnetwork/tonbags-sdk) to place storage orders. + +**Installation** + +```sh +$ npm install @crustnetwork/tonbags-sdk @ton/ton @ton/core @ton/crypto +``` + +**Usage** + +```javascript +import tonbagssdk from '@crustnetwork/tonbags-sdk' +import { default_storage_period } from "@crustnetwork/tonbags-sdk/src/TonBags"; +import { Address, toNano } from "@ton/core"; +import { mnemonicToPrivateKey } from "@ton/crypto"; +import { TonClient, WalletContractV4 } from "@ton/ton"; + +const tc = new TonClient({ + endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC", +}); +const tonbagsAddress = Address.parse( + "EQBOOMNqG0rvNm6vFGfR4qZl48BTDw_gYefVI4DQ70t9GoPC" +); +const tonBags = tonbagssdk.TonBags.createFromAddress(tonbagsAddress); + +const openTonBags = tc.open(tonBags); +const keyPair = await mnemonicToPrivateKey(["your", "mnemonic"]); +const wallet = tc.open( + WalletContractV4.create({ workchain: 0, publicKey: keyPair.publicKey }) +); +await openTonBags.sendPlaceStorageOrder( + wallet.sender(keyPair.secretKey), + tonrrentHash, // torrentHash or bagId + 1024n, // fileSize + merkleHash, // file merkle tree root hash + toNano("0.1"), // storageFee + default_storage_period // storage period time +); +``` + +Before placing order, the file need be encoded into a merkle tree, and the root hash need be passed to TONBag storage contract. Below is the code example: + +```javascript +import { merkle } from '@crustnetwork/tonbags-sdk' + +const readAsBlob = async (file: string) => { + return new Promise((resolve, reject) => { + let chunks: Buffer[] = []; + fs.createReadStream(file) + .on("error", reject) + .on("data", (data: Buffer) => { + chunks.push(data); + }) + .on("end", () => resolve(new Blob(chunks))); + }); +}; + +const mt = new merkle.MerkleTree(); +const blob = await readAsBlob("test.txt"); +// generate merkle tree +await mt.genTree(blob); +// merkle tree root +const merkleRoot = mt.tree![0]; +``` \ No newline at end of file