# Voting for a Validator

### Vote/Stake to a Validator

{% tabs %}
{% tab title="UI" %}

Step1: Navigate to <https://dao.rei.network/#/stake>&#x20;

![](https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FrY5VVAURxFbBZqo7kzpN%2F2022-06-28%2014.09.20.png?alt=media\&token=35228444-d447-4583-aa4f-bafc437d4e57)

Step2: Click on `Voting to Validator`, enter validator `address` and submit the `amount` you want to stake/vote

![](https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FOnKKHXoCwA9apfhjxPqq%2F2022-06-28%2014.11.27.png?alt=media\&token=58120f98-eb43-4d4e-841a-b79ac9484501)
{% endtab %}

{% tab title="Ethers" %}

```typescript
import { getDefaultProvider, Wallet } from "ethers";
import { StakeManager__factory } from "@rei-network/contracts";

const provider = getDefaultProvider("https://rpc-mainnet.rei.network");

const wallet = new Wallet("yourPrivateKey", provider);

const stakeManager = StakeManager__factory.connect(
  "0x0000000000000000000000000000000000001001",
  wallet
);

stakeManager
  .stake("validatorAddress", "receiveAddress", {
    value: "stakeAmount",
  })
  .then(() => {
    // ...
  })
  .catch(() => {
    // ...
  });
```

{% endtab %}
{% endtabs %}

> #### Why am I not able to Stake?&#x20;
>
> Check if you have `REI` in your wallet on REI Network
>
> #### I've staked to 0x...abcd, but not record find in ACTIVE VALIDATOR?
>
> Because only the 21 nodes with the most votes are currently displayed in the list of activated nodes

### UnVote/UnStake

{% tabs %}
{% tab title="UI" %}
Once you log in you will find this on the Validator of the Staking Dashboard. Here you will see an `Unstake` button for each of the validators. Click on the `Unstake` button for whichever validator that you had staked to.

![](https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FvnkOP4JTCEhOL13GjVEY%2F2022-06-28%2014.15.19.png?alt=media\&token=7f6b7d33-c4a9-4612-bbf6-2118f9eb2f69)
{% endtab %}

{% tab title="Ethers" %}

```typescript
import { getDefaultProvider, Wallet, BigNumber } from "ethers";
import {
  CommissionShare__factory,
  StakeManager__factory,
  CommissionShare,
} from "@rei-network/contracts";

const provider = getDefaultProvider("https://rpc-mainnet.rei.network");

const wallet = new Wallet("yourPrivateKey", provider);

const stakeManager = StakeManager__factory.connect(
  "0x0000000000000000000000000000000000001001",
  wallet
);

(async () => {
  try {
    let cs: CommissionShare;
    // get commission share contract address from validators
    {
      const result = await stakeManager.validators("validatorAddress");
      cs = CommissionShare__factory.connect(result.commissionShare, wallet);
    }

    // approve for stake manager
    {
      const tx = await cs.approve(
        "0x0000000000000000000000000000000000001001",
        "approveAmount"
      );
      await tx.wait();
    }

    // start unstake
    {
      const tx = await stakeManager.startUnstake(
        "validatorAddress",
        "receiveAddress",
        "numberOfShares"
      );
      await tx.wait();
      const receipt = await provider.getTransactionReceipt(tx.hash);
      for (const log of receipt.logs) {
        if (
          log.address === "0x0000000000000000000000000000000000001001" &&
          log.topics[0] ===
            "0x020b3ba91672f551cfd1f7abf4794b3fb292f61fd70ffd5a34a60cdd04078e50" // StartUnstake event topic
        ) {
          const bn = BigNumber.from(log.topics[1]);
          console.log("your unstakeId is:", bn.toNumber());
          break;
        }
      }
    }
  } catch (err) {
    // ...
  }
})();
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Note: There will be a **vesting period** after unvote/unstake, find the pending unstake record in \`Pending Unstake\` Dashboard
{% endhint %}

### Claim Vested Stake

{% tabs %}
{% tab title="UI" %}
You can find unstake list in `Pending Unstaked` Dashboard.

Once the vesting period is completed, the `UNSTAKE` button will be enabled and you can then claim your staked tokens to your wallet now.

![](https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FQshdX1U9LIBL3broErwv%2F2022-06-28%2011.58.00.png?alt=media\&token=77dbac26-901f-4cab-a4e6-0de94480df8d)
{% endtab %}

{% tab title="Ethers" %}

```typescript
import { getDefaultProvider, Wallet } from "ethers";
import { StakeManager__factory } from "@gxchain2/contracts";

const wallet = new Wallet(
  "yourPrivKey",
  getDefaultProvider("https://rpc-mainnet.rei.network")
);

const stakeManager = StakeManager__factory.connect(
  "0x0000000000000000000000000000000000001001",
  wallet
);

stakeManager
  .unstake("unstakeId")
  .then(() => {
    // ...
  })
  .catch((err) => {
    // ...
  });
```

{% endtab %}
{% endtabs %}
