Skip to content

Commit

Permalink
Update TONBags wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
gavfu committed Aug 15, 2024
1 parent 3c8eb7e commit 865bfe6
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
4 changes: 4 additions & 0 deletions website/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
],
"Build With TON": [
"tonBuildOverview",
"tonBuild101"
"tonBuild101",
"tonApplications"
],
"Node": [
"nodeOverview",
Expand Down
25 changes: 25 additions & 0 deletions website/translated_docs/zh-CN/ton-applications.md
Original file line number Diff line number Diff line change
@@ -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)
69 changes: 67 additions & 2 deletions website/translated_docs/zh-CN/ton-build-101.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Blob>((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];
```

0 comments on commit 865bfe6

Please sign in to comment.