Kagome
Polkadot Runtime Engine in C++17
|
In this tutorial you will learn how to execute Kagome-based Polkadot-host chain which can be used as a cryptocurrency, and interact with it by sending extrinsics and executing queries.
For your convenience make sure you have this binary included into your path:
```bash
PATH=$PATH:/build/node/ ```
Python 3 installed in the system with substrate-interface
package installed
> If you are not sure if you have requests package installed in your python run pip3 install substrate-interface
During this tutorial we will:
For this tutorial we will spin up a simple network of a single peer with predefined genesis.
To start with let's navigate into the node's folder:
first_kagome_chain
folder contains necessary configuration files for our tutorial:
localchain.json
– genesis file for our network. It contains necessary key-value pairs that should be inserted before the genesis blockbase_path
– Directory, containing kagome base path. It contains several dirs, each one named with the chain id, which data it stores (dev
in this case). Data for each chain consists of db/
(will be initialized on node startup) and keystore/
(keys to sign the messages sent by our authority). The latter has to exist prior to the node start. This behaviour will be improved in the future.localchain.json
contains Alice and Bob accounts. Both have 999998900.0 amount of crypto. Their keys can be generated using subkey tool:
If you are running this tutorial not for the first time, then make sure you cleaned up your storage as follows (assuming storage files are generated in ldb/ folder):
For this tutorial you can start a single node network as follows:
Let's look at this flags in detail:
Flag | Description |
---|---|
--validator | optional, enables validator mode |
--chain | mandatory, chainspec file path |
--base-path | mandatory, base kagome directory path |
--port | port for p2p interactions |
--rpc-port | port for RPC over HTTP |
--ws-port | port for RPC over Websocket protocol |
More flags info available by running kagome --help
.
You should see the log messages notifying about produced and finalized the blocks.
Now chain is running on a single node. To query it we can use localhost's ports 9933 for http- and 9944 for websockets-based RPCs.
Kagome blockchain is constantly producing new blocks, even if there were no transactions in the network.
Now open second terminal and go to the transfer folder, available from the projects root directory.
cd examples/transfer
This folder contains two python scripts:
balance.py <address> <account_id>
– executes query to kagome, which returns balance of provided account<address>
address node's http service<account_id>
id of account being queriedtransfer.py <address> <seed> <dest> <amount>
– sends provided extrinsic<address>
address node's http service<seed>
secret seed of source account<dest>
destination account<amount>
amount of crypto to be transferredLet's query current balance of Alice's account.
Let's do the same for the Bob's account.
We can generate extrinsic using the following command:
This command will create extrinsic that transfers 1 from Alice to Bob's account (Alice's account is defined by secret seed and Bob's account by account id).
To send extrinsic use transfer.py
script as follows:
Now let's check that extrinsic was actually applied:
Get the balance of Bob's account:
We can see that Bob's balance was increased by 1 as it was set on the subkey command
Now let's check Alice's account:
We can see that Alice's account was decreased by more than 1. This is caused by the commission paid for transfer
Now you know how to set up single peer kagome network and execute transactions on it