Localnet
On this page
Single Node #
Pre-requisite Readings #
Automated Localnet (script) #
You can customize the local testnet script by changing values for convenience for example:
# customize the name of your key, the chain-id, moniker of the node, keyring backend, and log level
KEY="mykey"
CHAINID="ICPlaza_13141619-4"
MONIKER="localtestnet"
KEYRING="test"
LOGLEVEL="info"
# Allocate genesis accounts (ICPlaza formatted addresses)
ICPlazad add-genesis-account $KEY 100000000000000000000000000aICPlaza --keyring-backend $KEYRING
# Sign genesis transaction
ICPlazad gentx $KEY 1000000000000000000000aICPlaza --keyring-backend $KEYRING --chain-id $CHAINID
The default configuration will generate a single validator localnet with the chain-id ICPlazad-1
and one predefined account (mykey
) with some allocated funds at the genesis.
You can start the local chain using:
init.sh
Manual Localnet #
This guide helps you create a single validator node that runs a network locally for testing and other development related uses.
Initialize the chain #
Before actually running the node, we need to initialize the chain, and most importantly its genesis file. This is done with the init
subcommand:
$MONIKER=testing
$KEY=mykey
$CHAINID="ICPlaza_9000-4"
# The argument $MONIKER is the custom username of your node, it should be human-readable.
ICPlazad init $MONIKER --chain-id=$CHAINID
::: tip You can [edit] this moniker
later by updating the config.toml
file. :::
The command above creates all the configuration files needed for your node and validator to run, as well as a default genesis file, which defines the initial state of the network. All these [configuration files] are in ~/.ICPlazad
by default, but you can overwrite the location of this folder by passing the --home
flag.
Genesis Procedure #
Adding Genesis Accounts #
Before starting the chain, you need to populate the state with at least one account using the keyring:
ICPlazad keys add my_validator
Once you have created a local account, go ahead and grant it some ICTech tokens in your chain’s genesis file. Doing so will also make sure your chain is aware of this account’s existence:
ICPlazad add-genesis-account my_validator 10000000000aICPlaza
Now that your account has some tokens, you need to add a validator to your chain.
For this guide, you will add your local node (created via the init
command above) as a validator of your chain. Validators can be declared before a chain is first started via a special transaction included in the genesis file called a gentx
:
# Create a gentx
# NOTE: this command lets you set the number of coins.
# Make sure this account has some coins with the genesis.app_state.staking.params.bond_denom denom
ICPlazad add-genesis-account my_validator 1000000000stake,10000000000aICPlaza
A gentx
does three things:
Registers the
validator
account you created as a validator operator account (i.e. the account that controls the validator).Self-delegates the provided
amount
of staking tokens.Link the operator account with a Tendermint node pubkey that will be used for signing blocks. If no
--pubkey
flag is provided, it defaults to the local node pubkey created via theICPlazad init
command above.
For more information on gentx
, use the following command:
ICPlazad gentx --help
Collecting gentx
#
gentx
#By default, the genesis file do not contain any gentxs
. A gentx
is a transaction that bonds staking token present in the genesis file under accounts
to a validator, essentially creating a validator at genesis. The chain will start as soon as more than 2/3rds of the validators (weighted by voting power) that are the recipient of a valid gentx
come online after genesis_time
.
A gentx
can be added manually to the genesis file, or via the following command:
# Add the gentx to the genesis file
ICPlazad collect-gentxs
This command will add all the gentxs
stored in ~/.ICPlazad/config/gentx
to the genesis file.
Run Testnet #
Finally, check the correctness of the genesis.json
file:
ICPlazad validate-genesis
Now that everything is set up, you can finally start your node:
ICPlazad start
:::tip To check all the available customizable options when running the node, use the --help
flag. :::
You should see blocks come in.
The previous command allow you to run a single node. This is enough for the next section on interacting with this node, but you may wish to run multiple nodes at the same time, and see how consensus happens between them.
You can then stop the node using Ctrl+C
.
Multi Node #
Automated Localnet with Ignite CLI #
Once you have installed ignite
, just run the localnet by using
ignite chain serve
Detailed instructions can be found in the Ignite CLI documentation
Automated Localnet with Docker #
Build & Start #
To build start a 4 node testnet run:
make localnet-start
This command creates a 4-node network using the ICTechnode
Docker image. The ports for each node are found in this table:
ICTechnode0
26656
26657
8545
8546
ICTechnode1
26659
26660
8547
8548
ICTechnode2
26661
26662
8549
8550
ICTechnode3
26663
26664
8551
8552
To update the binary, just rebuild it and restart the nodes
make localnet-start
The command above command will run containers in the background using Docker compose. You will see the network being created:
...
Creating network "ICPlaza_localnet" with driver "bridge"
Creating ICPlazadnode0 ... done
Creating ICPlazadnode2 ... done
Creating ICPlazadnode1 ... done
Creating ICPlazadnode3 ... done
Stop Localnet #
Once you are done, execute:
make localnet-stop
Configuration #
The make localnet-start
creates files for a 4-node testnet in ./build
by calling the ICPlazad testnet
command. This outputs a handful of files in the ./build
directory:
tree -L 3 build/
build/
├── ICPlazad
├── ICPlazad
├── gentxs
│ ├── node0.json
│ ├── node1.json
│ ├── node2.json
│ └── node3.json
├── node0
│ ├── ICPlazad
│ │ ├── key_seed.json
│ │ └── keyring-test-ICPlaza
│ └── ICPlazad
│ ├── config
│ ├── data
│ └── ICPlazad.log
├── node1
│ ├── ICPlazad
│ │ ├── key_seed.json
│ │ └── keyring-test-ICPlaza
│ └── ICPlazad
│ ├── config
│ ├── data
│ └── ICPlazad.log
├── node2
│ ├── ICPlazad
│ │ ├── key_seed.json
│ │ └── keyring-test-ICPlaza
│ └── ICPlazad
│ ├── config
│ ├── data
│ └── ICPlazad.log
└── node3
├── ICPlazad
│ ├── key_seed.json
│ └── keyring-test-ICPlaza
└── ICPlazad
├── config
├── data
└── ICPlazad.log
Each ./build/nodeN
directory is mounted to the /ICPlazad
directory in each container.
Logging #
In order to see the logs of a particular node you can use the following command:
# node 0: daemon logs
docker exec ICPlazadnode0 tail ICPlazad.log
# node 0: REST & RPC logs
docker exec ICPlazadnode0 tail ICPlazad.log
The logs for the daemon will look like:
I[2020-07-29|17:33:52.452] starting ABCI with Tendermint module=main
E[2020-07-29|17:33:53.394] Can't add peer's address to addrbook module=p2p err="Cannot add non-routable address 272a247b837653cf068d39efd4c407ffbd9a0e6f@192.168.10.5:26656"
E[2020-07-29|17:33:53.394] Can't add peer's address to addrbook module=p2p err="Cannot add non-routable address 3e05d3637b7ebf4fc0948bbef01b54d670aa810a@192.168.10.4:26656"
E[2020-07-29|17:33:53.394] Can't add peer's address to addrbook module=p2p err="Cannot add non-routable address 689f8606ede0b26ad5b79ae244c14cc67ab4efe7@192.168.10.3:26656"
I[2020-07-29|17:33:58.828] Executed block module=state height=88 validTxs=0 invalidTxs=0
I[2020-07-29|17:33:58.830] Committed state module=state height=88 txs=0 appHash=90CC5FA53CF8B5EC49653A14DA20888AD81C92FCF646F04D501453FD89FCC791
I[2020-07-29|17:34:04.032] Executed block module=state height=89 validTxs=0 invalidTxs=0
I[2020-07-29|17:34:04.034] Committed state module=state height=89 txs=0 appHash=0B54C4DB1A0DACB1EEDCD662B221C048C826D309FD2A2F31FF26BAE8D2D7D8D7
I[2020-07-29|17:34:09.381] Executed block module=state height=90 validTxs=0 invalidTxs=0
I[2020-07-29|17:34:09.383] Committed state module=state height=90 txs=0 appHash=75FD1EE834F0669D5E717C812F36B21D5F20B3CCBB45E8B8D415CB9C4513DE51
I[2020-07-29|17:34:14.700] Executed block module=state height=91 validTxs=0 invalidTxs=0
::: tip You can disregard the Can't add peer's address to addrbook
warning. As long as the blocks are being produced and the app hashes are the same for each node, there should not be any issues. :::
Whereas the logs for the REST & RPC server would look like:
I[2020-07-30|09:39:17.488] Starting application REST service (chain-id: "7305661614933169792")... module=rest-server
I[2020-07-30|09:39:17.488] Starting RPC HTTP server on 127.0.0.1:8545 module=rest-server
...
Follow Logs #
You can also watch logs as they are produced via Docker with the --follow
(-f
) flag, for example:
docker logs -f ICPlazadnode0
Interact with the Localnet #
Ethereum JSON-RPC & Websocket Ports #
To interact with the testnet via WebSockets or RPC/API, you will send your request to the corresponding ports:
8545
8546
You can send a curl command such as:
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' -H "Content-Type: application/json" 192.162.10.1:8545
::: tip The IP address will be the public IP of the docker container. :::
Additional instructions on how to interact with the WebSocket can be found on the events documentation.
Keys & Accounts #
To interact with ICPlazad
and start querying state or creating txs, you use the ICPlazad
directory of any given node as your home
, for example:
ICPlazad keys list --home ./build/node0/ICPlazad
Now that accounts exists, you may create new accounts and send those accounts funds!
::: tip Note: Each node’s seed is located at ./build/nodeN/ICPlazad/key_seed.json
and can be restored to the CLI using the ICPlazad keys add --restore
command :::
Special Binaries #
If you have multiple binaries with different names, you can specify which one to run with the BINARY environment variable. The path of the binary is relative to the attached volume. For example:
# Run with custom binary
BINARY=ICTech make localnet-start
Testnet command #
The ICTech testnet
subcommand makes it easy to initialize and start a simulated test network for testing purposes.
In addition to the commands for running a node, the /doc/DAPP/Ethereum/Events
binary also includes a testnet
command that allows you to start a simulated test network in-process or to initialize files for a simulated test network that runs in a separate process.
Initialize Files #
The init-files
subcommand initializes the necessary files to run a test network in a separate process (i.e. using a Docker container). Running this command is not a prerequisite for the start
subcommand ([see below]).
This is similar to the init
command when initializing a single node, but in this case we are initializing multiple nodes, generating the genesis transactions for each node, and then collecting those transactions.
In order to initialize the files for a test network, run the following command:
ICPlazad testnet init-files
You should see the following output in your terminal:
Successfully initialized 4 node directories
The default output directory is a relative .testnets
directory. Let’s take a look at the files created within the .testnets
directory.
Gentxs #
The gentxs
directory includes a genesis transaction for each validator node. Each file includes a JSON encoded genesis transaction used to register a validator node at the time of genesis. The genesis transactions are added to the genesis.json
file within each node directory during the initialization process.
Nodes #
A node directory is created for each validator node. Within each node directory is a ICTech directory. The ICTech directory is the home directory for each node, which includes the configuration and data files for that node (i.e. the same files included in the default ~/.
ICTech directory when running a single node).
Start Testnet #
The start
subcommand both initializes and starts an in-process test network. This is the fastest way to spin up a local test network for testing purposes.
You can start the local test network by running the following command:
ICPlazad testnet start
You should see something similar to the following:
acquiring test network lock
preparing test network with chain-id "ICPlaza_1276974-1"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++ THIS MNEMONIC IS FOR TESTING PURPOSES ONLY ++
++ DO NOT USE IN PRODUCTION ++
++ ++
++ sustain know debris minute gate hybrid stereo custom ++
++ divorce cross spoon machine latin vibrant term oblige ++
++ moment beauty laundry repeat grab game bronze truly ++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
starting test network...
started test network
press the Enter Key to terminate
The first validator node is now running in-process, which means the test network will terminate once you either close the terminal window or you press the Enter key. In the output, the mnemonic phrase for the first validator node is provided for testing purposes. The validator node is using the same default addresses being used when initializing and starting a single node (no need to provide a --node
flag).
Check the status of the first validator node:
ICPlazad status
Import the key from the provided mnemonic:
ICPlazad keys add test --recover
Check the balance of the account address:
ICPlazad q bank balances [address]
Use this test account to manually test against the test network.
Testnet Options #
You can customize the configuration of the test network with flags. In order to see all flag options, append the --help
flag to each command.
Last updated