# CLI

The CLI serves two purposes:

* Synchronizing blocks & transactions with your dashboard
* Synchronizing contract's artifact data for Truffle projects

{% hint style="info" %}
Artifact data for Hardhat projects are synchronized with a [plugin](https://doc.tryethernal.com/getting-started/hardhat-project-setup)
{% endhint %}

### Installation

Install the CLI globally with the following command:

```bash
npm install -g ethernal
```

### Logging In

If you haven't done so already, this is the first thing to do after installing.\
Your email is stored in `~/.config/configstore/ethernal.email.json`.\
Your password is stored in your local keychain.\
You only need to login once. If you need to log in with another account, you can just run the command again.

```bash
ethernal login
```

You can also skip the login command and use env variables:

```bash
ETHERNAL_EMAIL=your@email.com ETHERNAL_PASSWORD=yourpwd ethernal listen
```

### Listening to transactions

To listen to transactions, the CLI will pull the server address of the latest used workspace. If you want to specify a different workspace you can use the `-w` flag.

```bash
ethernal listen
```

Or for a different workspace:

```bash
ethernal listen -w staging
```

If the passed workspace name is not found, it will default to the latest used.

{% hint style="info" %}
When starting the CLI, it will automatically synchronize all blocks & transactions that are missing (if some happened when the CLI wasn't running for example).
{% endhint %}

### Watching contracts artifacts (Truffle projects only)

{% hint style="warning" %}
If you are using Hardhat, head to [this section](https://doc.tryethernal.com/getting-started/hardhat-project-setup).
{% endhint %}

The CLI will also watch by default your artifacts if you have run it in a Truffle project (there needs to be a truffle-config.js file in the directory).

If you are looking to set up a Truffle project:

{% content-ref url="truffle-project-setup" %}
[truffle-project-setup](https://doc.tryethernal.com/getting-started/truffle-project-setup)
{% endcontent-ref %}

If your chain is not running locally and you don't want to listen to transactions, but only synchronize artifacts, you can run

```bash
ethernal listen -l
```

And if you are on a remote server hosting the chain, and you don't want to watch for contracts, you can run:

```bash
ethernal listen -s
```

By default, only the name and the ABI of the contract are going to be uploaded. If you want to use the "Storage" tab of contracts page, you'll need to have the AST uploaded as well. To do so, pass the `--astUpload` flag as a parameter (this will upload the ast field, as well as the source field).

```
ethernal listen --astUpload
```

### Parameters

| Parameter | Alias     | Description                                                                                                           | Default                     |
| --------- | --------- | --------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| -w        | workspace | Specify the workspace to connect to                                                                                   | Latest used / First Created |
| -d        | dir       | Specify the directory to watch for artifact change. You can pass multiple parameters by using a comma as a separator. | . (current directory)       |
| -s        | server    | Do not watch for artifact change - only listen for transactions                                                       | false                       |
| -a        | astUpload | Upload AST to decode storage                                                                                          | true                        |
| -l        | local     | Do not listen for transactions - only watch for contract changes                                                      | false                       |

### Resetting a workspace

This will delete all accounts/blocks/transactions/contracts from a specific workspace

```bash
ethernal reset [workspace]
```
