-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: revise development docs (#851)
- Loading branch information
1 parent
b9a7cb4
commit 28ee2d4
Showing
15 changed files
with
275 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.