# Operating and Running a Node

{% hint style="info" %}
If you are considering joining as a validator, first follow this guide, then continue with [validator-onboarding](https://docs.seda.xyz/home/for-chain-operators/seda-chain-guide-and-requirements/validator-onboarding "mention") and [seda-keys](https://docs.seda.xyz/home/for-chain-operators/seda-chain-guide-and-requirements/seda-keys "mention").
{% endhint %}

**Contents**

[#running-the-node-yourself](#running-the-node-yourself "mention")\
[#running-the-node-with-cosmovisor](#running-the-node-with-cosmovisor "mention")\
[#running-the-node-yourself-dockerized](#running-the-node-yourself-dockerized "mention")

### Running the Node Yourself

```bash
# Rename the downloaded binary to a simpler name.
mv sedad-${ARCH} sedad
# mv sedad-amd64 sedad
# mv sedad-arm64 sedad

# Make the downloaded binary executable.
chmod +x sedad

# This documentation assumes that you have added the binary to $PATH as well.

# Reset the chain.
sedad tendermint unsafe-reset-all
rm -rf ~/.sedad || true

# Create your operator key.
sedad keys add <key-name>

# Initialize your node and join the network.
# Choose mainnet or testnet.
# Use the recover flag to use an existing key.
sedad join <moniker> --network mainnet [--recover]

# Start your node.
sedad start
```

### Running the Node with Cosmovisor

Run the node as a subprocess of Cosmovisor if you want automatic upgrading, which only requires you to place a new binary in the right location before an upgrade height.

Install Cosmovisor.

```bash
go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest
```

Then, add these lines to your profile (maybe `.profile`, `.zprofile`, or something else) to set up environment variables:

```bash
echo "# Cosmovisor Setup" >> ~/.profile
echo "export DAEMON_NAME=sedad" >> ~/.profile
echo "export DAEMON_HOME=$HOME/.sedad" >> ~/.profile
echo "export DAEMON_ALLOW_DOWNLOAD_BINARIES=false" >> ~/.profile
echo "export DAEMON_LOG_BUFFER_SIZE=512" >> ~/.profile
echo "export DAEMON_RESTART_AFTER_UPGRADE=true" >> ~/.profile
echo "export UNSAFE_SKIP_BACKUP=true" >> ~/.profile
source ~/.profile
```

Initialize Cosmovisor with the chain binary and start the node.

```bash
cosmovisor init sedad
cosmovisor run start
```

Note that for an upgrade, simply run the following command to prepare Cosmovisor with the upgrade binary before the chain reaches the upgrade height.

```bash
cosmovisor add-upgrade <upgrade-name> <upgrade-binary-file>
```

### Running the Node Yourself Dockerized

{% hint style="info" %}
Docker support is currently limited for the SEDA testnet since it has undergone an upgrade. The SEDA team is planning to add state sync support for the Docker environment soon.
{% endhint %}

#### Starting

To start a SEDA chain node with Docker (only recommended for those familiar with the tool):

```bash
docker run -d --name seda_node \
-p 26656:26656 \
-p 26657:26657 \
-p 9090:9090 \
--env MONIKER=<your_moniker> \
--env NETWORK=mainnet \
ghcr.io/sedaprotocol/seda-chain:v0.1.1 sedad start
```

Note the version `v0.1.1`, which is the chain binary version used for the mainnet launch. Exposing the ports is optional.

To check the status of the node you can check the normal `docker` way:

```bash
docker logs seda_node -n 100
```

or by interacting with the CLI from within the container:

```bash
docker exec seda_node sedad status
```

#### Upgrading

When an upgrade proposal is passed, node operators are expected to use Cosmovisor to prepare the node for an automatic upgrade. Since the Docker image provided by SEDA is already configured to use Cosmovisor, simply run the following commands to download and place the upgrade binary inside the container.

```bash
UPGRADE_NAME=v0.0.7 # upgrade name example

wget https://github.com/sedaprotocol/seda-chain/releases/download/$UPGRADE_NAME/sedad-amd64
chmod +x sedad-amd64
docker exec seda_node mkdir -p /home/seda/.sedad/cosmovisor/upgrades/$UPGRADE_NAME/bin
docker cp sedad-amd64 seda_node:/home/seda/.sedad/cosmovisor/upgrades/$UPGRADE_NAME/bin/sedad
```

#### **Stopping and Resuming**

The docker container should can be stopped and resumed as follows:

```bash
docker stop seda_node

# This runs it as a background process handled by docker.
docker start seda_node
```

**License**\
Contents of this repository are open source under [GNU General Public License v3.0](https://github.com/sedaprotocol/seda-chain/blob/main/LICENSE).
