Skip to content

Commit

Permalink
docs: revise development docs (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
sameh-farouk authored Aug 24, 2023
1 parent b9a7cb4 commit 28ee2d4
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 252 deletions.
2 changes: 1 addition & 1 deletion bridge/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ See [installing](./install.md)

## Prerequisites:

- Install and run [tfchain](https://github.com/threefoldtech/tfchain/blob/development/docs/development/development.md)
- Install and run [tfchain](https://github.com/threefoldtech/tfchain/blob/development/docs/development)
- Install [stellar-utils-tool](https://github.com/threefoldfoundation/tft/tree/main/bsc/bridges/stellar/utils)

## Local single node development
Expand Down
2 changes: 1 addition & 1 deletion bridge/docs/multinode.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ In this document we will explain how you can setup a local multinode instance of

## Step 1: Run tfchain

See [tfchain](https://github.com/threefoldtech/tfchain/blob/development/docs/development/development.md)
See [tfchain](https://github.com/threefoldtech/tfchain/blob/development/docs/development)

Create a twin on your local chain:

Expand Down
2 changes: 1 addition & 1 deletion bridge/docs/single_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ In this document we will explain how you can setup a local single node instance

## Step 1: Create a Twin on tfchain

Make sure [tfchain](https://github.com/threefoldtech/tfchain/blob/development/docs/development/development.md) is up and running.
Make sure [tfchain](https://github.com/threefoldtech/tfchain/blob/development/docs/development) is up and running.

Create a twin on your local chain:

Expand Down
98 changes: 98 additions & 0 deletions docs/development/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Development

You can find everything related to getting started with development on TFchain here.

## Learn the basics

Check [substrate learn topics](https://docs.substrate.io/learn/) which cover the fundamental concepts and terminology to start building your blockchain using the Substrate framework.

After you digest the information in these introductory sections, you'll be ready to start tinkering with TFchain development.

## Setup development environment

See [how to setup your development environment](./setup_development_environment.md) document.

## Get the TFchain node code

```sh
git clone https://github.com/threefoldtech/tfchain.git
```

## Compile TFchain binary

```sh
cd tfchain/substrate-node
cargo build
```

## Run a dev node
A dev node is a single-node network that runs on your local machine. It is useful for testing and debugging purposes. To run a dev node, you need to do the following:

```sh
cd tfchain/substrate-node
cargo build

./target/debug/tfchain --dev --ws-external --pruning archive
```
This will run the node in default development mode. This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`, `--alice`, and `--tmp` flags, unless explicitly overridden.

## Run multiple local nodes

If you want to run tfchain in a multi node network (more than one node), see [local](./local_multinode.md)

## Basic operations

You can use the Polkadot JS Apps ui to connect to your dev node. You can access the web interface at https://polkadot.js.org/apps/ and change the settings to use a local node with the address `ws://127.0.0.1:9944`.

This will allow you to interact with your dev node and perform basic operations.
- Use the Polkadot JS Apps to interact with your nodes. You can access the web interface at https://polkadot.js.org/apps/ and change the settings to use a local node or a remote node with the appropriate address.
- Use the `Accounts` tab to manage your accounts and balances. You can create new accounts, import existing accounts, transfer tokens, and view your transaction history.
- Use the `Explorer` tab to view the network status and activity. You can see the latest blocks, events, validators, and peers.
- Use the `Chain State` tab to query the state of the network. You can select a module and a storage item and see its value at any given block.
- Use the `Extrinsics` tab to submit extrinsics to the network. You can select an account, a module, and a function and provide any required parameters.

## Create an account

An account is a pair of public and private keys that represents your identity and allows you to perform transactions on the tfchain network.

See [how to an create account](./create_devnet_account.md).

## Code changes ?

Wipe data and recompile.

### Data cleanup:

```sh
./target/debug/tfchain purge-chain
```

Note: you don't need to wipe data when you run a node with `--dev` flag and no explicit `--base-path`. this because `--tmp` option is implied which create a temporary directory to store the configuration on node start that will be deleted at the end of the process.

## Fork-Off-Substrate tool

To experiment with different features and parameters of TFchain, See [here](./fork-off-substrate.md) how you can use `fork-off-substrate` tool to create a local fork of the TFchain network.

## How to develop a pallet

A pallet is a modular component that defines some logic and functionality for the tfchain network. You can develop your own custom pallets using macros, add them to the runtime, and test their functionality.

To learn about pallet development, you can start by checking these resources:

- Get start by reading The substrate [Build application logic tutorials](https://docs.substrate.io/tutorials/build-application-logic/). these tutorials focus on how you can customize the runtime using pallets, creating a custom pallet using macros, adding it to the runtime, and testing its functionality.

- Check the [the Substrate collectibles workshop](https://docs.substrate.io/tutorials/collectibles-workshop/runtime-and-pallets/). This is an interactive, hands-on, and self-paced workshop that introduces the basic steps for building a blockchain-based application using Substrate.

- Explore other existing pallets on the [Substrate GitHub repository](https://github.com/paritytech/substrate/tree/master/frame) and learn from their code. You can see how different pallets implement different features and patterns, such as storage, events, errors, hooks, traits, weights, origins, calls, etc.


## Writing tests for pallets

Every pallet should have all functionality tested, you can write unit tests and integration tests for a pallet:

- Unit tests: check this [guide](https://docs.substrate.io/reference/how-to-guides/testing/)
- Integration tests: see this [document](../../substrate-node/tests/readme.md)

## Upgrading Substrate version

See [how to upgrade substrate version](./upgrade_substrate.md).
20 changes: 0 additions & 20 deletions docs/development/create_account.md

This file was deleted.

70 changes: 70 additions & 0 deletions docs/development/create_devnet_account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Creating And Funding An Account on TFChain Development network

## the TF dashboard flow:

**Caution**: This option allows you to create and store your account locally in your browser. However, you need strong backup policy as this method is not very secure and you may lose your account if you clear your browser data.

- Visit https://dashboard.dev.grid.tf and click on the `Generate Account` button.
- Read the ThreeFold Grid USER/FARMER TERMS AND CONDITIONS and click on the `Accept Terms and Conditions` button.
- You will see a 12-word mnemonic phrase (click on the eye icon to toggle the visibility). This is your private key, so write it down and keep it safe. You also need to choose a password that will encrypt the mnemonic in your browser local storage.
- After you have saved the mnemonic securely and confirmed your password, click on the `Connect` button. You can use the password on the same machine and browser to access your wallet without entering the mnemonic. Now your account was created and activated on the TFchain development network.

## Alternative flows:
Note: The methods mentioned below are outdated and no longer work.
### Polkadot-JS UI flow:

**caution**: This option allows you to create and store your account locally in your browser. However, this is not very secure and you may lose your account if you clear your browser data. To use this option, you need to:

- Step 1: Browse to the Polkadot JS Apps UI

You can use these link to access it:
- Using a public node: https://polkadot.js.org/apps/?rpc=wss://tfchain.dev.grid.tf/ws#/
- Using a private node: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944/ws#/


- Step 2: Enable in-browser Account Creation

To enable account creation on Polkadot-JS UI, navigate to the Settings tab. In the account options, choose `allow local in-browser account storage` and click Save.

Note: This option is provided for advanced users with strong backup policies. It is recommended that you store all keys externally to the in-page browser local storage, either on browser extensions, signers operating via QR codes or hardware devices.

- step 3: Navigate to the "Accounts" page

Should look something like this:

![image](https://user-images.githubusercontent.com/13766992/130954090-c34193eb-0864-4f6a-aa49-7ce66b6d72fb.png)

- Step 4: Create New Account

- Click "Add Account"

![image](https://user-images.githubusercontent.com/13766992/130955887-b6e87bc4-64d5-49ff-b6ac-fa6ac2ebc90d.png)

- Once pressed you'll see a 12-word mnemonic phrase. Save it safely (Make sure to save your mnemonic phrase now, as there is no way to view it after the account is created) and check the box saying you have done so and press next.
- Enter a name for your account in the Name field. This is just a label for your convenience and does not affect the functionality of the account.
- Enter a password for your account in the Password and Confirm Password fields. This is used to encrypt your private key locally and protect your account from unauthorized access.
- Optionally, you can choose a different derivation path for your account in the Advanced creation options section. This is an advanced feature that allows you to generate different accounts from the same seed phrase. You can leave it as default if you are not familiar with it.
- Optionally, click on the Advanced creation options section to expand it.
- You will see a drop-down menu labeled Key type. This is where you can select the type of cryptographic algorithm for your account’s key pair.
- The default option is sr25519, which is a Schnorr signature scheme that offers high performance and security. You can also choose ed25519, which is an Edwards curve signature scheme that is widely used and compatible with many platforms. Both options support Substrate-based networks and Polkadot.

- After you select your preferred key type, you can proceed to click on the Save button and create your account.

- Step 5: Fund your account

- On the same page, on the left top, hover over `Account` button and click on `Transfer`.
- First select account `Alice` and secondly select your newly created account from the list.
- Send any amount to your account.

### Polkadot browser extension flow:

This option allows you to create and store your account in a separate browser extension that can be accessed from any website. This is more secure and convenient than the in-browser storage option. To use this option, you need to:

- step 1: Install the Polkadot JS Extension for your browser (Chrome, Firefox, or Brave).
- step 2: Click on the extension icon on your browser toolbar and then click on the + button and select `Create new account` to create a new account.
- step 3: You will see your secret seed phrase (Generated 12-WORD mnemonic seed), which you must write down and keep safe. mark the box beside `I have stored my mnemonic seed safely` and click on the `Next step` button.
- step 4: Follow the instructions to generate a new account. Leave the network as it is, and choose a name, and a password.
- step 5: Click on the `Add the account with the generated seed` button to store your account in the extension. You will see your account address and icon on the extension popup. You can also export your account as a JSON file for backup purposes.


Once you have created and stored your account using either option, you can use it to interact with TFchain or any Substrate-based. You can also create multiple accounts for different purposes using different derivation paths.
51 changes: 0 additions & 51 deletions docs/development/development.md

This file was deleted.

55 changes: 55 additions & 0 deletions docs/development/fork-off-substrate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Fork off substrate

The fork-off-substrate tool is a handy tool that allows you to download and run a copy of any Substrate-based blockchain on your local machine. You can use it to experiment with different features and parameters of the blockchain for learning or development purposes.

In this guide, we will show you how to use the tool to create a local fork of the TFchain network.

### Prerequisites
Before you start, you need to have the following items:

- The executable binary and the runtime WASM blob of the target blockchain. You can either compile them from the source code of the blockchain project, or copy them from a trusted node that runs the blockchain. For TFchain, you can find the source code [here](https://github.com/threefoldtech/tfchain) and the instructions on how to compile it [here](https://github.com/threefoldtech/tfchain/tree/development/docs/development). Find the Wasm binary file in the target directory. The file name should be `tfchain_runtime.compact.wasm` and the file path should be something like this:

```bash
./substrate-node/target/debug/wbuild/tfchain-runtime/tfchain_runtime.compact.wasm
```

### Steps
- Install the `fork-off-substrate` tool dependencies on your computer, go to `tfchain` directory then follow these steps:
```bash
cd ./tools/fork-off-substrate
npm i
```
- Create a folder called data inside the top folder (fork-off-substrate).
```bash
mkdir data
```
- Copy the executable/binary of your substrate based node inside the data folder and rename it to `binary`
```bash
cp ../../substrate-node/target/debug/tfchain ./data/binary
```
- Copy the runtime WASM blob of your substrate based blockchain to the data folder and rename it to `runtime.wasm`.
```bash
cp ../../substrate-node/target/debug/wbuild/tfchain-runtime/tfchain_runtime.compact.wasm ./data/runtime.wasm
```
- Run a full node for your blockchain locally (Recommended but should be fully synced) or have an external endpoint handy (but should be running with `--rpc-methods Unsafe` flag)
```bash
../../substrate-node/target/debug/tfchain --chain ../../substrate-node/chainspecs/dev/chainSpecRaw.json --ws-external --rpc-methods Unsafe
```
- Run the script

- If using a local node, simply run the script using
```bash
npm start
```

- If you are using an external/non-default endpoint, you need to provide it to the script via the HTTP_RPC_ENDPOINT environment variable
```bash
HTTP_RPC_ENDPOINT=https://<EXTERNAL END POINT> npm start
```
- You should have the genesis file for the forked chain inside the data folder. It will be called `fork.json`.
- You can now run a new chain using this genesis file
```bash
./data/binary --chain ./data/fork.json --alice
```

for more information about this tool, you can read this [blog post](https://mudit.blog/fork-substrate-blockchain/).
18 changes: 11 additions & 7 deletions docs/development/local_multinode.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Local tfchain network

This document will explain how to run a local multi node tfchain network.
This document will explain how to run a local multiple-node tfchain network.

## Compile release build
## Compile

```sh
cd substrate-node
cargo build --release
cargo build
```

you can
## Start the network

In a terminal window execute the following command:

```sh
./target/release/tfchain \
./target/debug/tfchain \
--base-path /tmp/alice \
--chain local \
--alice \
Expand All @@ -30,7 +31,7 @@ This will start a first node.
In a second terminal window executing the following command:

```sh
./target/release/tfchain \
./target/debug/tfchain \
--base-path /tmp/bob \
--chain local \
--bob \
Expand Down Expand Up @@ -91,6 +92,9 @@ Before moving on, have a look at how the following options are used to start the
- --telemetry-url Specifies where to send telemetry data. For this tutorial, you can send telemetry data to a server hosted by Parity that is available for anyone to use.
- --validator Specifies that this node participates in block production and finalization for the network.
## More information
Can be found here: https://docs.substrate.io/tutorials/get-started/simulate-network/
## What next
You can now interact with the local multiple-node network using the hosted [Polkadot JS Apps portal](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer) or the [Substrate front-end template](https://github.com/substrate-developer-hub/substrate-front-end-template).
More information can be found here: https://docs.substrate.io/tutorials/get-started/simulate-network/
Loading

0 comments on commit 28ee2d4

Please sign in to comment.