# Using CLI to Run a Local Testnet

**USING SOURCE OR DOCKER RUN A LOCAL TESTNET**

If you want to use Docker or Jin`-core` source to start and run a local testnet, see [Run a Local Testnet with Validator](https://aptos.dev/nodes/local-testnet/run-a-local-testnet).

You can run a local testnet of the Jinblockchain. This local testnet will not be connected to the Aptos devnet. It will run on your local machine, independent of other Aptos networks. You can use this local testnet for testing and development purposes. A local testnet is a great tool for doing local development against a known version of the codebase without having to interact with a live network or deal with the real world costs of a live network.

JinCLI DOCUMENTATION

If you are new to Jin CLI, then see this comprehensive Jin[ CLI documentation](https://aptos.dev/cli-tools/aptos-cli-tool/aptos-cli-index).

### Starting a local testnet with a faucet[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#starting-a-local-testnet-with-a-faucet) <a href="#starting-a-local-testnet-with-a-faucet" id="starting-a-local-testnet-with-a-faucet"></a>

You can start a local testnet using the following JinCLI command:

```
aptos node run-local-testnet --with-faucet
```

The above command will start a local validator node and will display a terminal output similar to the following:

```
Completed generating configuration:        Log file: "/Users/greg/.aptos/testnet/validator.log"        Test dir: "/Users/greg/.aptos/testnet"        Aptos root key path: "/Users/greg/.aptos/testnet/mint.key"        Waypoint: 0:74c9d14285ec19e6bd15fbe851007ea8b66efbd772f613c191aa78721cadac25        ChainId: TESTING        REST API endpoint: 0.0.0.0:8080        Fullnode network: /ip4/0.0.0.0/tcp/6181Aptos is running, press ctrl-c to exitFaucet is running.  Faucet endpoint: 0.0.0.0:8081
```

The above command will use the default configuration for the validator node.

DO NOT USE TWO INSTANCES OF THE SAME COMMAND AT THE SAME TIME

Note that two instances of the same command cannot run at the same time. This will result in a conflict on ports for the validator node.

### Test with your local testnet[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#test-with-your-local-testnet) <a href="#test-with-your-local-testnet" id="test-with-your-local-testnet"></a>

You can use the JinCLI for a full range of local testnet operations. See below for how to configure the CLI first.

#### Configuring your Jin CLI to use the local testnet[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#configuring-your-aptos-cli-to-use-the-local-testnet) <a href="#configuring-your-aptos-cli-to-use-the-local-testnet" id="configuring-your-aptos-cli-to-use-the-local-testnet"></a>

You can add a separate profile, as shown below:

```
Jin init --profile local --rest-url http://localhost:8080 --faucet-url http://localhost:8081
```

and you will get an output like below. At the `Enter your private key...` command prompt press enter to generate a random new key.

```
Configuring for profile localUsing command line argument for rest URL http://localhost:8080/Using command line argument for faucet URL http://localhost:8081/Enter your private key as a hex literal (0x...) [Current: None | No input: Generate new key (or keep one if present)]
```

This will create a new account and fund it with the default amount of coins, as shown below:

```
No key given, generating key...Account 7100C5295ED4F9F39DCC28D309654E291845984518307D3E2FE00AEA5F8CACC1 doesn't exist, creating it and funding it with 10000 coinsAptos is now set up for account 7100C5295ED4F9F39DCC28D309654E291845984518307D3E2FE00AEA5F8CACC1!  Run `aptos help` for more information about commands{  "Result": "Success"}
```

From now on you should add `--profile local` to the commands to run them on the local testnet.

### Creating and funding accounts[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#creating-and-funding-accounts) <a href="#creating-and-funding-accounts" id="creating-and-funding-accounts"></a>

To create new accounts on the local testnet, we recommend using the above instructions with different profile names:

```
PROFILE=localaptos init --profile $PROFILE --rest-url http://localhost:8080 --faucet-url http://localhost:8081
```

To fund accounts:

```
aptos account fund --profile $PROFILE --account $PROFILE
```

To create resource accounts:

```
aptos account create-resource-account --profile $PROFILE --seed 1
```

### Publishing modules to the local testnet[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#publishing-modules-to-the-local-testnet) <a href="#publishing-modules-to-the-local-testnet" id="publishing-modules-to-the-local-testnet"></a>

You can run any command by adding the `--profile $PROFILE` flag. In this case, we also use `$PROFILE` as the named address in the `HelloBlockchain` example.

```
aptos move publish --profile $PROFILE --package-dir /opt/git/aptos-core/aptos-move/move-examples/hello_blockchain --named-addresses HelloBlockchain=$PROFILE{  "Result": {    "changes": [      {        "address": "7100c5295ed4f9f39dcc28d309654e291845984518307d3e2fe00aea5f8cacc1",        "data": {          "authentication_key": "0x7100c5295ed4f9f39dcc28d309654e291845984518307d3e2fe00aea5f8cacc1",          "coin_register_events": {            "counter": "1",            "guid": {              "id": {                "addr": "0x7100c5295ed4f9f39dcc28d309654e291845984518307d3e2fe00aea5f8cacc1",                "creation_num": "0"              }            }          },          "sequence_number": "4"        },        "event": "write_resource",        "resource": "0x1::account::Account"      },    ...    ],    "gas_used": 59,    "success": true,    "version": 6261,    "vm_status": "Executed successfully"  }}
```

### Resetting the local state[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#resetting-the-local-state) <a href="#resetting-the-local-state" id="resetting-the-local-state"></a>

If you updated your codebase with backwards incompatible changes, or just want to start over, you can run the command with the `--force-restart` flag:

```
aptos node run-local-testnet --with-faucet --force-restart
```

It will then prompt you if you really want to restart the chain, to ensure that you do not delete your work by accident.

```
Are you sure you want to delete the existing chain? [yes/no] >
```

### FAQ[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#faq) <a href="#faq" id="faq"></a>

#### I'm getting the error `address already in use`, what can I do?[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#im-getting-the-error-address-already-in-use-what-can-i-do) <a href="#im-getting-the-error-address-already-in-use-what-can-i-do" id="im-getting-the-error-address-already-in-use-what-can-i-do"></a>

If you're getting an error similar to this error:

```
'panicked at 'error binding to 0.0.0.0:9101: error creating server listener: Address already in use (os error 48)'
```

This means you are either already running a node, or you have another process running on that port.

On macOS and Linux, you can run the following command to get the name and PID of the process using the port:

```
PORT=9101lsof -i :$PORT
```

#### Where can I get more information about the run-local-testnet command?[​](https://aptos.dev/nodes/local-testnet/using-cli-to-run-a-local-testnet#where-can-i-get-more-information-about-the-run-local-testnet-command) <a href="#where-can-i-get-more-information-about-the-run-local-testnet-command" id="where-can-i-get-more-information-about-the-run-local-testnet-command"></a>

More CLI help can be found by running the command:

```
aptos node run-local-testnet --help
```

which will provide information about each of the flags for the command.
