Skip to content

Commit

Permalink
Merge pull request #141 from gosh-sh/oxanas/ack-59-js-sample-of-integ…
Browse files Browse the repository at this point in the history
…ration-with-acki-nacki-2

WIP
  • Loading branch information
Oxydixi authored Jul 30, 2024
2 parents a551f1f + 2a8972b commit 6e69d53
Show file tree
Hide file tree
Showing 49 changed files with 2,901 additions and 61 deletions.
29 changes: 16 additions & 13 deletions docs/acki-nacki/connection-to-network/create-giver.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## **Create wallet-contract**


To create your own giver, using any contract of wallet.

For example, create file `giver.sol` with following content:
To create your own wallet, use for example, the contract of a `Simple wallet`.

Create a file called `wallet.sol` with the following content:

```solidity
pragma ton-solidity >= 0.35.0;
Expand Down Expand Up @@ -55,10 +56,10 @@ Compile this contract using the following [instruction](./create-and-compile-con

As a result, you will have 4 files:

* `giver.sol` - source code of your wallet-contract;
* `giver.code` - it contains the assembly code of the contract;
* `giver.tvc` - binary code of your contract (the contents of this file will be deployed on network);
* `giver.abi.json` - describe the interface of the contract.
* `wallet.code` - it contains the assembly code of the contract;
* `wallet.tvc` - binary code of your contract (the contents of this file will be deployed on network);
* `wallet.sol` - source code of your wallet-contract;
* `wallet.abi.json` - describe the interface of the contract.


## **Deploy**
Expand All @@ -76,14 +77,15 @@ export PATH=$PATH:<PATH_TO>/tvm-cli
tvm-cli config --url ackinacki-testnet.tvmlabs.dev
```

2) Generate address, keys and seed phrase for your giver:
2) Generate address, keys and seed phrase for your wallet:

```shell
tvm-cli genaddr giver.tvc --genkey giver.keys.json
tvm-cli genaddr wallet.tvc --genkey wallet.keys.json
```

Address of your contract in the blockchain is located after `Raw address:`

<!-- TODO update image -->
![](../../images/n_Acki_Nacki_c_t_n_giver_genn_addr.jpg)

!!! Warning "IMPORTANT"
Expand All @@ -92,7 +94,7 @@ Address of your contract in the blockchain is located after `Raw address:`
We will refer to it as **`<YourAddress>`** below.

**Seed phrase** is also printed to stdout.
**Key pair** will be generated and saved to the file **`giver.keys.json`**.
**Key pair** will be generated and saved to the file **`wallet.keys.json`**.


!!! danger
Expand All @@ -117,30 +119,31 @@ tvm-cli account <YourAddress>
```

You will see something similar to the following:

<!-- TODO update image -->
![](../../images/n_Acki_Nacki_c_t_n_giver_account.jpg)

5) Deploy your contract to the early configured network with the following command:

```shell
tvm-cli deploy --abi giver.abi.json --sign giver.keys.json giver.tvc {}
tvm-cli deploy --abi wallet.abi.json --sign wallet.keys.json wallet.tvc {}
```

!!! info

The arguments of the constructor must be specified in curly brackets:
`{<constructor arguments>}`


<!-- TODO update image -->
![](../../images/n_Acki_Nacki_c_t_n_giver_deploy.jpg)

6) Check the contract state again. This time, it is should be `Active`.

<!-- TODO update image -->
![](../../images/n_Acki_Nacki_c_t_n_giver_account2.jpg)

## **Request test tokens for future use**

To replenish your giver, please contact us in [Channel on Telegram](https://t.me/+1tWNH2okaPthMWU0).
To replenish your wallet, please contact us in [Channel on Telegram](https://t.me/+1tWNH2okaPthMWU0).

## **Source code**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
## **Prerequisites**

* Rust v.1.76+
* Node.js v.18
* [Wallet-contract](./create-giver.md) to be used as a giver with keys
* Contract, for example: [`helloWorld.sol`](./create-and-compile-contract.md)
* [Demo application](https://github.com/gosh-sh/gosh-examples/tree/main/sdk/javascript/helloWorld)
* Rust v1.76+
* Node.js v18.19.1
* Python 3
* Python 3 setuptools
<!-- TODO giver to wallet -->
* [Wallet-contract](./create-giver.md) to be used for payment for deploying contract
* Demo contract [`helloWorld.sol`](./create-and-compile-contract.md)
* [Demo application](https://github.com/tvmlabs/sdk-examples/tree/main/apps/javascript/helloWorld)


**This demo app implements the following logic:**
**This demo app implements the following scenario:**

1. Creates and initializes an instance of the SDK client;

2. Deploys the `helloWorld` contract:

3.1 Generates key pair for the contract;
2.1 Generates key pair for the contract;

3.2 Calculates future address of the contract;
2.2 Calculates future address of the contract;

3.3 Sends to the future address of the contract some tokens required for deploy;
2.3 Sends to the future address of the contract some tokens required for deploy;

3.4 Deploys the `helloWorld` contract;
2.4 Deploys the `helloWorld` contract;

3. Gets account info and print balance of the `helloWorld` contract

Expand All @@ -32,10 +35,9 @@
7. Sends some tokens from `helloWorld` contract to a random account



!!! warning "Important"

**For the application to work, you should to place `ABI files` of the `wallet` and `helloWorld` contracts in the `contracts` folder.**
**For the application to work, you should to place `ABI files` of the `wallet` and `helloWorld` contracts into the `contracts` folder.**

!!! info

Expand All @@ -45,57 +47,81 @@
To replenish the balance of wallet-contract, please contact us in [Channel on Telegram](https://t.me/+1tWNH2okaPthMWU0).


## **Setup giver**

Before you start, you should setup a wallet-contract to be used as a giver.
Edit `.env` file with following content:
We will do all the work in this quick start in a separate `~/test-sdk` folder.
Let's create it:

```
CONTRACT_CODE=PATH_TO_HELLOWORLD_CONTRACT_CODE # helloWorld.tvc
GIVER_ADDRESS=YOUR_WALLET_ADDRESS
GIVER_KEYS=PATH_TO_YOUR_WALLET_KEYS_FILE
cd ~
mkdir test-sdk
```

## **Preparation for work**
## **Prepare SDK binding for JavaScript**


1. Install the packages `@eversdk/core` and `@eversdk/lib-node` for the Node.js application:
1.Clone the repository to a separate directory:

```
npm install --save @eversdk/core @eversdk/lib-node
cd ~/test-sdk
git clone https://github.com/tvmlabs/tvm-sdk-js.git
```

2. Replace the binary file in `@eversdk/lib-node` with an Acki Nacki-compatible one:
2.Run build:

```
cd tvm-sdk-js/packages/lib-node/build
cargo run
```

As a result, the builded binding `eversdk.node` will be placed into the folder `~/test-sdk/tv-sdk-js/packages/lib-node`.


2.1. Clone the repository to a separate directory:
## **Prepare demo application**


1.Clone repository contains the demo application:

```
git clone https://github.com/gosh-sh/ever-sdk-js
cd ~/test-sdk
git clone https://github.com/tvmlabs/sdk-examples.git
cd sdk-examples/apps/javascript/helloWorld
```

2.2. Switch to the "feature/masterchain-free" branch:
2.By this point, you should have deployed a wallet from which the balances of your demo contracts will be replenished.
You can do this by following [the instructions](./create-giver.md).


3.Configure wallet for using in the demo app:

For demo app working, you should configure the wallet.
To do this, in the demo folder, edit `.env` file with following content:

<!-- TODO rename giver to wallet -->

```
cd ever-sdk-js
git checkout feature/masterchain-free
CONTRACT_CODE=PATH_TO_HELLOWORLD_CONTRACT_CODE # helloWorld.tvc
GIVER_ADDRESS=YOUR_WALLET_ADDRESS
GIVER_KEYS=PATH_TO_YOUR_WALLET_KEYS_FILE
```

3. Run the build:
3.Install the packages `@eversdk/core` and `@eversdk/lib-node` for the demo application:

```
cd packages/lib-node/build
cargo run
npm install --save @eversdk/core @eversdk/lib-node
```

4. Copy the built file to the specified folder: `<YOUR_NODEJS_APP>/node_modules/@eversdk/lib-node`:
4.Replace the binary file in `@eversdk/lib-node` with an Acki Nacki-compatible one, which was builded early:

```
cp ../eversdk.node <YOUR_NODEJS_APP>/node_modules/@eversdk/lib-node/
cp ~/test-sdk/tv-sdk-js/packages/lib-node/eversdk.node ~/test-sdk/gosh-examples/sdk/javascript/helloWorld/node_modules/@eversdk/lib-node/
```


## **Run it**

Go to the folder with the demo application and run it:

```
cd ~/test-sdk/gosh-examples/sdk/javascript/helloWorld
node index.js
```

Expand Down
20 changes: 20 additions & 0 deletions site/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,26 @@



<li class="md-nav__item">
<a href="/acki-nacki/connection-to-network/quick-start-tvm-sdk-JavaScript/" class="md-nav__link">


<span class="md-ellipsis">
Quick start for TVM SDK JavaScript
</span>


</a>
</li>









<li class="md-nav__item">
<a href="/acki-nacki/connection-to-network/create-and-compile-contract/" class="md-nav__link">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



<link rel="prev" href="../quick-start-tvm-sdk/">
<link rel="prev" href="../quick-start-tvm-sdk-JavaScript/">


<link rel="next" href="../create-giver/">
Expand Down Expand Up @@ -1482,6 +1482,26 @@




<li class="md-nav__item">
<a href="../quick-start-tvm-sdk-JavaScript/" class="md-nav__link">


<span class="md-ellipsis">
Quick start for TVM SDK JavaScript
</span>


</a>
</li>











Expand Down
Loading

0 comments on commit 6e69d53

Please sign in to comment.