# Stake using Creditcoin CLI

#### Running from the Docker image <a href="#running-from-the-docker-image" id="running-from-the-docker-image"></a>

Make sure your Creditcoin Node container is running and use Creditcoin CLI via the `docker exec` command.

```
docker exec -it creditcoin-validator creditcoin --help
```

{% hint style="danger" %}
Security notes:\
\
When using docker, employ `docker exec` as specified in these docs to keep sensitive values out of the container's logs on your system.

Only use the Creditcoin CLI to administer a validator from its own machine or container. Do not use the Creditcoin CLI to remotely administer a validator even on the same LAN or virtual network. Connections to the node, from the Creditcoin CLI, are made over unencrypted and unauthenticated websockets and are only safe for use on the loopback interface. (i.e `localhost`, `127.0.0.1`)

Remember that, when using any terminal or command line tool, commands entered in your terminal window are visible to other users and services on your system. Only enter secrets like seed phrases when prompted by the Creditcoin CLI.
{% endhint %}

#### Creating Accounts <a href="#creating-accounts" id="creating-accounts"></a>

Create an account using the `new` command and write down the seed phrase.

```
docker exec creditcoin-validator creditcoin new
```

The output should look like the following:

```
Creating new seed phrase...
Seed phrase: owner amateur hungry hockey clerk size parrot jump rural mad pretty gauge
```

Use `show-address` to get the address for the account by entering the seed phrase, so you can fund it with a transfer. This will be the Stash account that will hold all tokens meant for staking.

```
docker exec -it creditcoin-validator creditcoin show-address
```

Output:

```
✔ Specify a seed phrase for the caller account … *************************************************************************
Account Substrate address: 5CUnLxUCFqtGkre7MZwyX66E3kPMKDXra4FYtiYp5SoDUwKM
Associated EVM address: 0x125cff2b5d2e00c0a0b632a7c1979c19bf70ac22
```

#### Funding Your Account <a href="#funding-your-account" id="funding-your-account"></a>

Once your account is created, make sure it has enough CTC to cover the desired staking amount *plus* transaction fees. To fund an account, you can transfer from another wallet using a number of tools such as [Subwallet](https://www.subwallet.app/), [Talisman](https://www.talisman.xyz/), the [PolkadotJS extension](/wallets/how-to-connect-your-wallet-to-creditcoin/polkadot-js-extension.md) or [Creditcoin CLI](/wallets/how-to-connect-your-wallet-to-creditcoin/command-line-interface/creditcoin-cli.md).

The minimum amount of CTC required to become a validator&#x20;

* Mainnet: 0
* Testnet: 20000 CTC

You can confirm the balance of your account by following the directions mentioned in the [Checking your Balance section of the Creditcoin CLI 3 page](/wallets/how-to-connect-your-wallet-to-creditcoin/command-line-interface/creditcoin-cli.md).

#### Validator Wizard <a href="#validator-wizard" id="validator-wizard"></a>

Creditcoin CLI provides a simple Wizard to set up validators. `wizard` will prompt you for the previously generated seed phrase. After launching the wizard and providing it with the seed phrase, it will show us the complete validator setup options and prompt us to continue.

{% hint style="danger" %}
Security note:

Account’s private keys are derived from these seed phrases.

Every account must have a unique seed phrase.

Remember to use separate accounts (i.e. new seed phrases) for testnet and mainnet validators.
{% endhint %}

```
docker exec -it creditcoin-validator creditcoin wizard --amount <ctc-amount>
```

It will show the current staking settings, make sure to check them before continuing.

```
🧙 Running staking wizard...
Using the following parameters:
💰 Stash account: 5CUnLxUCFqtGkre7MZwyX66E3kPMKDXra4FYtiYp5SoDUwKM
🪙  Amount to bond: 20000 CTC
🎁 Reward destination: Staked
📡 Node URL: ws://127.0.0.1:9944
💸 Commission: 0
🔐 Blocked: No
Continue? (y/n): y
```

After continuing, the Wizard will create all required extrinsics (i.e. transactions) and communicate with the node to pair it with the stash account.

Once the transactions are sent, the new validator should be in the waiting queue.

Use the status command to get information about the status of a particular validator by entering its Stash address.

```
docker exec -it creditcoin-validator creditcoin status --substrate-address 5CGBosx2Fw34u9jJtSgEQkoNTtHkPLKgsfjJiE3mDSWb44MW
```

The validator status will be shown:

```
Validator 5CGBosx2Fw34u9jJtSgEQkoNTtHkPLKgsfjJiE3mDSWb44MW:
┌────────────────┬──────┐
│ Status         │      │
├────────────────┼──────┤
│ Bonded         │ Yes  │
├────────────────┼──────┤
│ Validating     │ Yes  │
├────────────────┼──────┤
│ Waiting        │ Yes  │
├────────────────┼──────┤
│ Active         │ No   │
├────────────────┼──────┤
│ Can withdraw   │ No   │
├────────────────┼──────┤
│ Next unlocking │ None │
└────────────────┴──────┘
```

If the validator shows up as Waiting the setup has been successful and it will become active if it gets enough backing.

#### Manual Setup <a href="#manual-setup" id="manual-setup"></a>

Setting a validator can also be done by sending each required command manually.

First bond CTC using your Stash account and enter the CTC amount to stake.

```
docker exec -it creditcoin-validator creditcoin bond --amount <ctc-amount>
```

Set the validator node keys. The `--rotate` flag specifies that the node will generate new keys. Existing keys can be used with the `--keys <key-string>` option.

```
docker exec -it creditcoin-validator creditcoin set-keys --rotate
```

Once keys are set up, the last step is signaling the network the intention to validate. Use the `--commission <commission-percent>` option to set up a portion of the block reward that will not be shared with nominators or the `--blocked` flag to block nominations.

```
docker exec -it creditcoin-validator creditcoin validate --commission <commission-percent>
```

#### Distributing Rewards <a href="#distributing-rewards" id="distributing-rewards"></a>

It is conventionally the validator operator's responsibility to trigger the reward distribution at the end of every era. The address of the stash account doubles as the validator's ID when distributing rewards.

Remember, you can compute the stash account's address by running the following and providing the stash account's seed phrase when prompted:

```
docker exec -it creditcoin-validator creditcoin show-address
```

With the stash address in hand, run the `distribute-rewards` command.

```
docker exec -it creditcoin-validator creditcoin distribute-rewards --era <era number> --substrate-address <validator-address>
```

#### Stopping a Validator <a href="#stopping-a-validator" id="stopping-a-validator"></a>

Stop a running validator with the `chill` command. This will remove the validator from the active/waiting set in the next session.

```
docker exec -it creditcoin-validator creditcoin chill
```

#### Unbonding CTC <a href="#unbonding-ctc" id="unbonding-ctc"></a>

To unbond locked CTC, validators must first mark their tokens for unbonding, then wait for the unlocking period to end and finally withdraw the unbonded funds.

```
docker exec -it creditcoin-validator creditcoin unbond --amount <amount>
```

The status command shows when the next unlocking chunk will be available to withdraw.

```
docker exec -it creditcoin-validator creditcoin status --substrate-address <stash-address>
```

```
Validator 5CGBosx2Fw34u9jJtSgEQkoNTtHkPLKgsfjJiE3mDSWb44MW:
┌────────────────┬─────────────────────────────────┐
│ Status         │                                 │
├────────────────┼─────────────────────────────────┤
│ Bonded         │ Yes                             │
├────────────────┼─────────────────────────────────┤
│ Validating     │ Yes                             │
├────────────────┼─────────────────────────────────┤
│ Waiting        │ Yes                             │
├────────────────┼─────────────────────────────────┤
│ Active         │ No                              │
├────────────────┼─────────────────────────────────┤
│ Can withdraw   │ No                              │
├────────────────┼─────────────────────────────────┤
│ Next unlocking │1000 CTC in 6 minutes, 5 seconds │
└────────────────┴─────────────────────────────────┘
```

After the unbonding period has passed, withdraw the funds.

```
docker exec -it creditcoin-validator creditcoin withdraw-unbonded
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.creditcoin.org/validator-guides/stake-using-creditcoin-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
