-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add near-validator extension #2493
base: master
Are you sure you want to change the base?
Changes from all commits
a4e0208
8122ff1
fab0bcb
eef2a38
8668049
4fdbc48
4980046
7eb76da
b94188e
f1f2e91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,13 @@ Before delegating, you need to choose a validator (a node that participates in s | |
Once you select a validator and the stake transaction is confirmed, your tokens are delegated to the staking pool. | ||
You will start earning staking rewards after the next epoch (approximately 12 hours). | ||
|
||
:::info Delegation without a staking pool | ||
|
||
For validators, there's also an option to stake NEAR tokens without deploying a staking pool smart contract. | ||
Check [this section](../../4.tools/cli.md#staking) to learn how to stake using the [`near-validator`](../../4.tools/cli.md#validator-extension) CLI. | ||
|
||
::: | ||
|
||
### Selecting a Staking Pool | ||
|
||
Use [NearBlocks](https://nearblocks.io/node-explorer), [Pikespeak](https://pikespeak.ai/validators/overview) or [Near Staking](https://near-staking.com/) to find a validator and their staking pool. | ||
|
@@ -66,28 +73,74 @@ Look for validators with a good track record, uptime, and reasonable commission | |
|
||
::: | ||
|
||
If you prefer, you can get the list of current validators by using the [`near-validator`](../../4.tools/cli.md#validator-extension) CLI: | ||
|
||
```sh | ||
near-validator validators network-config mainnet now | ||
``` | ||
|
||
### Staking using CLI | ||
|
||
Once you have chosen a validator you want to delegate your tokens to, follow these steps to stake them using the NEAR CLI: | ||
|
||
1. Connect your wallet to the CLI and ensure you have NEAR tokens to delegate. | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near account import-account using-web-wallet network-config mainnet | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near login | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
|
||
2. Deposit tokens to the `<my_validator>` staking pool: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near call <my_validator> deposit '{}' --accountId <user-account.near> --amount 100 | ||
near contract call-function as-transaction <my_validator> deposit json-args {} prepaid-gas '30.0 Tgas' attached-deposit '100 NEAR' sign-as <user-account.near> network-config testnet sign-with-keychain send | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near call <my_validator> deposit '{}' --accountId <user-account.near> --deposit 100 | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
3. Stake the deposited tokens by calling the `stake` method: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near staking delegation <user-account.near> stake '100 NEAR' <my_validator> network-config mainnet sign-with-keychain | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near call <my_validator> stake '{"amount": "100000000000000000000000000"}' --accountId <user-account.near> | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
:::tip Interactive CLI | ||
|
||
If you want to manage your staking actions with an interactive CLI, use this command and follow the prompts on your screen: | ||
|
@@ -102,10 +155,23 @@ near staking delegation | |
|
||
Once the transaction is confirmed, your tokens are delegated to the staking pool. | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near staking delegation <user-account.near> view-balance <my_validator> network-config mainnet now | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near view <my_validator> get_account_staked_balance '{"account_id": "<user-account.near>"}' | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
:::info Using a wallet to check your staked tokens | ||
|
||
You can see your staked balance, rewards earned, and the validator you delegated to using a web3 wallet. For example, you can try `https://app.mynearwallet.com/profile/<user-account.near>`. | ||
|
@@ -121,18 +187,44 @@ The rewards are typically distributed periodically, and you will be able to see | |
|
||
To check your total balance on the `<my_validator>` pool: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near staking delegation <user-account.near> view-balance <my_validator> network-config mainnet now | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near view <my_validator> get_account_total_balance '{"account_id": "<user-account.near>"}' | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
#### User staked balance | ||
|
||
To check your staked balance on the `<my_validator>` pool: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near staking delegation <user-account.near> view-balance <my_validator> network-config mainnet now | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near view <my_validator> get_account_staked_balance '{"account_id": "<user-account.near>"}' | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
<details> | ||
<summary>Staking pool balances</summary> | ||
|
||
|
@@ -181,30 +273,82 @@ To un-delegate the tokens: | |
|
||
1. First execute the `unstake` method on the `<my_validator>` contract: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near staking delegation <user-account.near> unstake '1 NEAR' <my_validator> network-config mainnet sign-with-keychain | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it's worth mentioning, that as an alternative a user can unstake all NEAR tokens at once by calling |
||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near call <my_validator> unstake '{"amount": "100000000000000000000000000"}' --accountId <user-account.near> | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
2. Check the unstaked balance for your `<user-account.near>` account: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near staking delegation <user-account.near> view-balance <my_validator> network-config mainnet now | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near view <my_validator> get_account_unstaked_balance '{"account_id": "<user-account.near>"}' | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
3. After 4 epochs, check if you can withdraw: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near contract call-function as-read-only <my_validator> is_account_unstaked_balance_available json-args '{"account_id": "<user-account.near>"}' network-config mainnet now | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near view <my_validator> is_account_unstaked_balance_available '{"account_id": "<user-account.near>"}' | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
If the Validator's response is `true`, then your tokens are ready for the last step. | ||
|
||
4. Finally, withdraw the unstaked tokens: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near staking delegation <user-account.near> withdraw '1 NEAR' <my_validator> network-config mainnet sign-with-keychain | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same as above, a user can withdraw everything at once |
||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Short"> | ||
|
||
```sh | ||
near call <my_validator> withdraw '{"amount": "100000000000000000000000000"}' --accountId <user-account.near> | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
--- | ||
|
||
## Tools and Resources | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,37 @@ The NEAR [Command Line Interface](https://github.com/near/near-cli-rs) (CLI) is | |
</TabItem> | ||
</Tabs> | ||
|
||
### Validator Extension | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's move the installation guide down to the "Validators" section, as it's the only place on this page where it's actually needed |
||
|
||
If you want to interact with [NEAR Validators](https://pages.near.org/papers/economics-in-sharded-blockchain/#validators) from command line, you can also install the optional [NEAR Validator CLI Extension](https://github.com/near-cli-rs/near-validator-cli-rs): | ||
|
||
<Tabs> | ||
<TabItem value="npm"> | ||
|
||
```bash | ||
npm install -g near-validator | ||
``` | ||
</TabItem> | ||
<TabItem value="Cargo"> | ||
|
||
```bash | ||
$ cargo install near-validator | ||
``` | ||
</TabItem> | ||
<TabItem value="Mac and Linux (binaries)"> | ||
|
||
```bash | ||
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near-cli-rs/near-validator-cli-rs/releases/latest/download/near-validator-installer.sh | sh | ||
``` | ||
</TabItem> | ||
<TabItem value="Windows (binaries)"> | ||
|
||
```bash | ||
irm https://github.com/near-cli-rs/near-validator-cli-rs/releases/latest/download/near-validator-installer.ps1 | iex | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
--- | ||
|
||
## Configuration file | ||
|
@@ -540,4 +571,106 @@ This will allow you to change or modify the network connections for your CLI. | |
|
||
:::important | ||
We provide examples only of the most used commands. If you want to explore all options provided by `near-cli` use [the interactive mode](#interactive-mode). | ||
::: | ||
::: | ||
|
||
--- | ||
|
||
## Validators | ||
|
||
:::tip | ||
To use these commands, you **must** install the CLI [validator extension](#validator-extension). | ||
::: | ||
|
||
You can use the following commands to interact with the blockchain and view validator stats. There are three reports used to monitor validator status: | ||
|
||
- [Proposals](#proposals) | ||
- [Current validators](#current-validators) | ||
- [Next validators](#next-validators) | ||
|
||
### Proposals | ||
|
||
A proposal by a validator indicates they would like to enter the validator set, in order for a proposal to be accepted it must meet the minimum seat price. | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near-validator proposals network-config mainnet | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
### Current Validators | ||
|
||
This shows a list of active validators in the current epoch, the number of blocks produced, number of blocks expected, and online rate. Used to monitor if a validator is having issues. | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near-validator validators network-config mainnet now | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
### Next Validators | ||
|
||
This shows validators whose proposal was accepted one epoch ago, and that will enter the validator set in the next epoch. | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near-validator validators network-config mainnet next | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
### Staking | ||
|
||
For validators, there's also an option to stake NEAR tokens without deploying a staking pool smart contract. | ||
|
||
#### View validator stake | ||
|
||
To view the validator's stake on the last block, you need to enter in the terminal command line: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near-validator staking view-stake examples.testnet network-config testnet now | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
#### Stake directly without a staking pool | ||
|
||
To stake the amount you must enter in the terminal command line: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near-validator staking stake-proposal examples.testnet ed25519:AiEo5xepXjY7ChihZJ6AsfoDAaUowhPgvQp997qnFuRP '1500 NEAR' network-config testnet sign-with-keychain send | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
#### Unstake directly without a staking pool | ||
|
||
To unstake you must enter in the terminal command line: | ||
|
||
<Tabs groupId="cli-commands"> | ||
<TabItem value="Full"> | ||
|
||
```sh | ||
near-validator staking unstake-proposal examples.testnet ed25519:AiEo5xepXjY7ChihZJ6AsfoDAaUowhPgvQp997qnFuRP network-config testnet sign-with-keychain send | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no need to take deposit and stake actions apart, as it can be done within a single function call
near staking delegation <user-account.near> deposit-and-stake