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:
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:
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:
::: 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:
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:
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:
A gentx does three things:
Registers the
validatoraccount you created as a validator operator account (i.e. the account that controls the validator).Self-delegates the provided
amountof staking tokens.Link the operator account with a Tendermint node pubkey that will be used for signing blocks. If no
--pubkeyflag is provided, it defaults to the local node pubkey created via theICPlazad initcommand above.
For more information on gentx, use the following command:
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:
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:
Now that everything is set up, you can finally start your node:
:::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
Detailed instructions can be found in the Ignite CLI documentation
Automated Localnet with Docker #
Build & Start #
To build start a 4 node testnet run:
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
The command above command will run containers in the background using Docker compose. You will see the network being created:
Stop Localnet #
Once you are done, execute:
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:
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:
The logs for the daemon will look like:
::: 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:
Follow Logs #
You can also watch logs as they are produced via Docker with the --follow (-f) flag, for example:
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:
::: 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:
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:
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:
You should see the following output in your terminal:
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:
You should see something similar to the following:
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:
Import the key from the provided mnemonic:
Check the balance of the account 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