> For the complete documentation index, see [llms.txt](https://docs.swisstronik.com/swisstronik-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.swisstronik.com/swisstronik-docs/development/local-testnet.md).

# Local testnet

Below you can find the guide how to setup local Swisstronik testnet with one or multiple validators using Docker

## Single validator testnet

{% hint style="danger" %}
Apple M1 and M2 are not supported, even using QEMU. To fix it, we're working on fork of hardhat with enabled encryption which will simulate Swisstronik node behaviour
{% endhint %}

For convenient development and testing of your dApps we've prepared the [ghcr.io/sigmagmbh/swisstronik-chain:latest](https://github.com/SigmaGmbH/chain/pkgs/container/chain/103837866?tag=latest) Docker image which contains preconfigured network with one validator.

You can start local node by running:&#x20;

```sh
docker run --rm -it -p 0.0.0.0:26657:26657 \
    -p 0.0.0.0:8545:8545 -p 0.0.0.0:8546:8546 \
    ghcr.io/sigmagmbh/swisstronik-chain:latest swisstronikd start --minimum-gas-prices=0uswtr \
    --json-rpc.api eth,txpool,personal,net,debug,web3 \
    --api.enable --enclave.address 0.0.0.0:8999 \
    --json-rpc.address 0.0.0.0:8535 --json-rpc.ws-address 0.0.0.0:8546
```

## Multiple validators testnet

### Prerequisites

* Installed `swisstronikd` binary
* Cloned <https://github.com/SigmaGmbH/swisstronik-chain> repo

### Build and start

Before starting a local testnet run following command to generate `genesis.json` file with initial state of blockchain and multiple validator configs

```sh
swisstronikd testnet init-files --chain-id swisstronik_1291-1
```

This command will create `.testnets` folder with validator private keys, configuration, etc.

Now you can start your local testnet using [Docker](https://docs.docker.com/engine/install/) and docker-compose by running command below from root directory of cloned`swisstronik-chain` repo:

```sh
docker-compose -f local-network.yml up -d
```

The command above will run docker containers in the background using docker-compose. You will see created network and containers

```log
[+] Running 4/4
 ✔ Container node0  Started                                                                                                                              0.7s 
 ✔ Container node2  Started                                                                                                                              0.8s 
 ✔ Container node3  Started                                                                                                                              0.9s 
 ✔ Container node1  Started 
```

### Stop local testnet

Once you are done, execute:

```sh
docker-compose -f local-network.yml stop
```

### Logging

To see what happening inside node you can use following command:

```sh
docker logs node0 --tail 100lo
```

The logs will look like:

```log
5:12PM INF Replay: Done module=consensus server=node
5:12PM INF received complete proposal block hash=429C2151A0D4051562D3D78EE1E36FE3D16D09562BD5022B57224FEACC8BE17D height=24 module=consensus server=node
5:12PM INF finalizing commit of block hash={} height=24 module=consensus num_txs=0 root=0F7DF8D943CE72CDF81A586E3745FB84840EFF6F87E3F689B000FDF553766E78 server=node
5:12PM INF FeeMarket: baseFee was changed newBaseFee=40568907 oldBaseFee=46364465
5:12PM INF minted coins from module account amount=411946856427874uswtr from=mint module=x/bank
5:12PM INF executed block height=24 module=state num_invalid_txs=0 num_valid_txs=0 server=node
5:12PM INF commit synced commit=436F6D6D697449447B5B3332203136372031393320323535203230203139322031313420313730203634203134382031302032203231352031373720313637203233362031383320313435203136342032343020313231203130392031393620313532203020313534203938203136352031333720383220313934203138345D3A31387D
5:12PM INF committed state app_hash=20A7C1FF14C072AA40940A02D7B1A7ECB791A4F0796DC498009A62A58952C2B8 height=24 module=state num_txs=0 server=node
5:12PM INF indexed block exents height=24 module=txindex server=node
5:12PM INF Timed out dur=4978.917062 height=25 module=consensus round=0 server=node step=1
5:12PM INF received proposal module=consensus proposal={"Type":32,"block_id":{"hash":"C3BB0C05F9D6396D68B02F754F9607F93E841B9C3CE53DAE182252DCC1212E5A","parts":{"hash":"D2C8643A8A10D962E4129D93BB8E4E6F57EEA1E031A799395D38B5E4A2B5CC81","total":1}},"height":25,"pol_round":-1,"round":0,"signature":"HPfb6MgDucfKBg7jubkqp3xAtf6gbPoj8Ntt6i55jG4fiu8YMKy42Q4Q39H8uQhiqAbTWSm678OJssD9xU3gDA==","timestamp":"2023-07-10T17:12:56.985371954Z"} server=node
5:12PM INF received complete proposal block hash=C3BB0C05F9D6396D68B02F754F9607F93E841B9C3CE53DAE182252DCC1212E5A height=25 module=consensus server=node
5:12PM INF finalizing commit of block hash={} height=25 module=consensus num_txs=0 root=20A7C1FF14C072AA40940A02D7B1A7ECB791A4F0796DC498009A62A58952C2B8 server=node
```

{% hint style="info" %}
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.
{% endhint %}

### Follow logs[**​**](https://docs.evmos.org/protocol/evmos-cli/multi-nodes#follow-logs)

You can also watch logs as they are produced via Docker with the `--follow` (`-f`) flag, for example:

```sh
docker logs -f node0
```

### **Ethereum JSON-RPC & Websocket Ports**[**​**](https://docs.evmos.org/protocol/evmos-cli/multi-nodes#ethereum-json-rpc--websocket-ports)

To interact with the testnet via WebSockets or RPC/API, you will send your request to the corresponding ports:

| EVM JSON-RPC | Eth Websocket |
| ------------ | ------------- |
| `8545`       | `8546`        |

You can send a curl command such as:

```sh
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' -H "Content-Type: application/json" 192.162.10.1:8545
```
