Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ton libs #45

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions 01-wallet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ library:npmton
Next, we're going to install a JavaScript package named [ton](https://www.npmjs.com/package/ton) that will allow us to make TON API calls and manipulate TON objects. Install the package by opening terminal in the project directory and running:

```console
npm install ton ton-crypto ton-core
npm install @ton/ton @ton/crypto @ton/core
```

---
Expand Down Expand Up @@ -159,7 +159,7 @@ Create the file `step7.ts` with the following content:
network:testnet library:npmton
---
```ts
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4 } from "ton";

async function main() {
Expand All @@ -184,7 +184,7 @@ main();
network:mainnet library:npmton
---
```ts
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4 } from "ton";

async function main() {
Expand Down Expand Up @@ -302,7 +302,7 @@ network:testnet library:npmton
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4, TonClient, fromNano } from "ton";

async function main() {
Expand Down Expand Up @@ -335,7 +335,7 @@ network:mainnet library:npmton
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4, TonClient, fromNano } from "ton";

async function main() {
Expand Down Expand Up @@ -458,7 +458,7 @@ network:testnet library:npmton
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, internal } from "ton";

async function main() {
Expand Down Expand Up @@ -516,7 +516,7 @@ network:mainnet library:npmton
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, internal } from "ton";

async function main() {
Expand Down
2 changes: 1 addition & 1 deletion 01-wallet/test/npmton/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set -ev
npm init --yes
npm install dotenv
npm install ts-node
npm install ton ton-core ton-crypto
npm install @ton/ton @ton/core @ton/crypto
npm install @orbs-network/ton-access
npx ts-node step7.ts > step7.output.txt
diff step7.output.txt step7.expected.txt
Expand Down
10 changes: 5 additions & 5 deletions 01-wallet/test/npmton/step7.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

import { mnemonicToWalletKey } from "ton-crypto";
import { WalletContractV4 } from "ton";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4 } from "@ton/ton";

async function main() {
// open wallet v4 (notice the correct wallet version here)
const mnemonic = process.env.MNEMONIC;; // your 24 secret words (replace ... with the rest of the words)
// Update step7.expected.txt before running the test, since it depends on your wallet address
const mnemonic = process.env.MNEMONIC; // your 24 secret words
const key = await mnemonicToWalletKey(mnemonic!.split(" "));
const wallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });

Expand All @@ -17,4 +17,4 @@ async function main() {
console.log("workchain:", wallet.address.workChain);
}

main();
main();
4 changes: 2 additions & 2 deletions 01-wallet/test/npmton/step8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { WalletContractV4, TonClient, fromNano } from "ton";
import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4, TonClient, fromNano } from "@ton/ton";

async function main() {
// open wallet v4 (notice the correct wallet version here)
Expand Down
4 changes: 2 additions & 2 deletions 01-wallet/test/npmton/step9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, WalletContractV4, internal } from "ton";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, internal } from "@ton/ton";

async function main() {
// open wallet v4 (notice the correct wallet version here)
Expand Down
5 changes: 3 additions & 2 deletions 01-wallet/test/tonweb/step7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { mnemonicToKeyPair } from "tonweb-mnemonic";
import TonWeb from "tonweb";

async function main() {
const mnemonic = process.env.MNEMONIC; // your 24 secret words (replace ... with the rest of the words)
// Update step7.expected.txt before running the test, since it depends on your wallet address
const mnemonic = process.env.MNEMONIC; // your 24 secret words
const key = await mnemonicToKeyPair(mnemonic!.split(" "));

// open wallet v4 (notice the correct wallet version here)
Expand All @@ -21,4 +22,4 @@ async function main() {
console.log("workchain:", walletAddress.wc);
}

main();
main();
12 changes: 6 additions & 6 deletions 02-contract/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The recommended way to interact with contracts is to create a small TypeScript c
Use the following code in `wrappers/Counter.ts` to create the initial data cell for deployment:

```ts
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";

export default class Counter implements Contract {

Expand All @@ -183,7 +183,7 @@ export default class Counter implements Contract {
}
```

Notice a few interesting things about this TypeScript code. First, it depends on the package [ton-core](https://www.npmjs.com/package/ton-core) instead of [ton](https://www.npmjs.com/package/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`.
Notice a few interesting things about this TypeScript code. First, it depends on the package [@ton/core](https://www.npmjs.com/package/@ton/core) instead of [ton](https://www.npmjs.com/package/ton), which contains a small subset of base types and is therefore slower to change - an important feature when building a stable interface for our contract. Second, the code that creates the data cell mimics the FunC API and is almost identical to our `save_data()` FunC function. Third, we can see the derivation of the contract address from the code cell and data cell using the function `contractAddress`.

The actual deployment involves sending the first message that will cause our contract to be deployed. We can piggyback any message that is directed towards our contract. This can even be the increment message with op #1, but we will do something simpler. We will just send some TON coins to our contract (an empty message) and piggyback that. Let's make this part of our interface. Add the function `sendDeploy()` to `wrappers/Counter.ts` - this function will send the deployment message:

Expand Down Expand Up @@ -226,7 +226,7 @@ network:testnet
```ts
import * as fs from "fs";
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, Cell, WalletContractV4 } from "ton";
import Counter from "../wrappers/Counter"; // this is the interface class from step 7

Expand Down Expand Up @@ -286,7 +286,7 @@ network:mainnet
```ts
import * as fs from "fs";
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, Cell, WalletContractV4 } from "ton";
import Counter from "../wrappers/Counter"; // this is the interface class from step 7

Expand Down Expand Up @@ -501,7 +501,7 @@ network:testnet
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, Address } from "ton";
import Counter from "../wrappers/Counter"; // this is the interface class we just implemented

Expand Down Expand Up @@ -553,7 +553,7 @@ network:mainnet
---
```ts
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { mnemonicToWalletKey } from "ton-crypto";
import { mnemonicToWalletKey } from "@ton/crypto";
import { TonClient, WalletContractV4, Address } from "ton";
import Counter from "../wrappers/Counter"; // this is the interface class we just implemented

Expand Down
6 changes: 3 additions & 3 deletions 02-contract/test/counter.step10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Counter implements Contract {
const address = contractAddress(workchain, { code, data });
return new Counter(address, { code, data });
}

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {}

async sendDeploy(provider: ContractProvider, via: Sender) {
Expand All @@ -19,7 +19,7 @@ export default class Counter implements Contract {
bounce: false
});
}

async sendIncrement(provider: ContractProvider, via: Sender) {
const messageBody = beginCell()
.storeUint(1, 32) // op (op #1 = increment)
Expand All @@ -35,4 +35,4 @@ export default class Counter implements Contract {
const { stack } = await provider.get("counter", []);
return stack.readBigNumber();
}
}
}
6 changes: 3 additions & 3 deletions 02-contract/test/counter.step7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export default class Counter implements Contract {
const address = contractAddress(workchain, { code, data });
return new Counter(address, { code, data });
}

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {}

async sendDeploy(provider: ContractProvider, via: Sender) {
await provider.internal(via, {
value: "0.01", // send 0.01 TON to contract for rent
bounce: false
});
}
}
}
}
6 changes: 3 additions & 3 deletions 02-contract/test/counter.step9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Counter implements Contract {
const address = contractAddress(workchain, { code, data });
return new Counter(address, { code, data });
}

constructor(readonly address: Address, readonly init?: { code: Cell, data: Cell }) {}

async sendDeploy(provider: ContractProvider, via: Sender) {
Expand All @@ -19,9 +19,9 @@ export default class Counter implements Contract {
bounce: false
});
}

async getCounter(provider: ContractProvider) {
const { stack } = await provider.get("counter", []);
return stack.readBigNumber();
}
}
}
2 changes: 2 additions & 0 deletions 02-contract/test/deploy.step8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export async function run() {
console.log("deploy transaction confirmed!");
}

run();

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
2 changes: 2 additions & 0 deletions 02-contract/test/getCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export async function run() {
//console.log("value:", counterValue.toString());
console.log("value:", counterValue >= 1000000000000n ? "more than 1T" : "less than 1T");
}

run(); // only for testing purposes
File renamed without changes.
10 changes: 5 additions & 5 deletions 02-contract/test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ npm install ts-node
npm install @ton-community/func-js
npm install ton ton-core ton-crypto
npm install @orbs-network/ton-access
npx func-js stdlib.fc counter.fc --boc counter.cell
npx func-js counter.fc --boc counter.cell
npx ts-node deploy.step8.ts > deploy.step8.output.txt
COUNTER_ADDRESS=`cut -d : -s -f 2 < deploy.step8.output.txt` npx ts-node step9.ts > step9.output.txt
diff step9.output.txt step9.expected.txt
COUNTER_ADDRESS=`cut -d : -s -f 2 < deploy.step8.output.txt` npx ts-node step10.ts > step10.output.txt
diff step10.output.txt step10.expected.txt
COUNTER_ADDRESS=`cut -d : -s -f 2 < deploy.step8.output.txt` npx ts-node getCounter.ts > getCounter.output.txt
diff getCounter.output.txt getCounter.expected.txt
COUNTER_ADDRESS=`cut -d : -s -f 2 < deploy.step8.output.txt` npx ts-node sendIncrement.ts > sendIncrement.output.txt
diff sendIncrement.output.txt sendIncrement.expected.txt
2 changes: 2 additions & 0 deletions 02-contract/test/sendIncrement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ export async function run() {
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

run(); // only for testing purposes
8 changes: 4 additions & 4 deletions 03-client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ npm install
We will need to install a few more packages that will allow us to interact with TON Blockchain. We've seen these packages in action in the previous tutorial. Run the following in terminal:

```console
npm install ton ton-core ton-crypto
npm install @ton/ton @ton/core @ton/crypto
npm install @orbs-network/ton-access
```

Expand Down Expand Up @@ -209,7 +209,7 @@ import { useEffect, useState } from 'react';
import Counter from '../contracts/counter';
import { useTonClient } from './useTonClient';
import { useAsyncInitialize } from './useAsyncInitialize';
import { Address, OpenedContract } from 'ton-core';
import { Address, OpenedContract } from '@ton/core';

export function useCounterContract() {
const client = useTonClient();
Expand Down Expand Up @@ -292,7 +292,7 @@ Create the file `src/hooks/useTonConnect.ts` with the following content:

```ts
import { useTonConnectUI } from '@tonconnect/ui-react';
import { Sender, SenderArguments } from 'ton-core';
import { Sender, SenderArguments } from '@ton/core';

export function useTonConnect(): { sender: Sender; connected: boolean } {
const [tonConnectUI] = useTonConnectUI();
Expand Down Expand Up @@ -327,7 +327,7 @@ import Counter from '../contracts/counter';
import { useTonClient } from './useTonClient';
import { useAsyncInitialize } from './useAsyncInitialize';
import { useTonConnect } from './useTonConnect';
import { Address, OpenedContract } from 'ton-core';
import { Address, OpenedContract } from '@ton/core';

export function useCounterContract() {
const client = useTonClient();
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ rm -rf ./temp
npm create vite@latest temp -- --template react-ts
cd temp
npm install
npm install ton ton-core ton-crypto
npm install @ton/ton @ton/core @ton/crypto
npm install @orbs-network/ton-access
npm install vite-plugin-node-polyfills
cp -f ../vite.config.ts .
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/contracts/counter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "ton-core";
import { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell } from "@ton/core";

export default class Counter implements Contract {

Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/hooks/useCounterContract.step6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
import Counter from '../contracts/counter';
import { useTonClient } from './useTonClient';
import { useAsyncInitialize } from './useAsyncInitialize';
import { Address, OpenedContract } from 'ton-core';
import { Address, OpenedContract } from '@ton/core';

export function useCounterContract() {
const client = useTonClient();
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/hooks/useCounterContract.step7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Counter from '../contracts/counter';
import { useTonClient } from './useTonClient';
import { useAsyncInitialize } from './useAsyncInitialize';
import { useTonConnect } from './useTonConnect';
import { Address, OpenedContract } from 'ton-core';
import { Address, OpenedContract } from '@ton/core';

export function useCounterContract() {
const client = useTonClient();
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/hooks/useTonClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getHttpEndpoint } from '@orbs-network/ton-access';
import { TonClient } from 'ton';
import { TonClient } from '@ton/ton';
import { useAsyncInitialize } from './useAsyncInitialize';

export function useTonClient() {
Expand Down
2 changes: 1 addition & 1 deletion 03-client/test/src/hooks/useTonConnect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTonConnectUI } from '@tonconnect/ui-react';
import { Sender, SenderArguments } from 'ton-core';
import { Sender, SenderArguments } from '@ton/core';

export function useTonConnect(): { sender: Sender; connected: boolean } {
const [tonConnectUI] = useTonConnectUI();
Expand Down
Loading
Loading