Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
/ near-cli Public archive

General purpose command line tools for interacting with NEAR Protocol

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE-APACHE
Notifications You must be signed in to change notification settings

near/near-cli

NEAR CLI (command line interface)

Gitpod Ready-to-Code

NEAR CLI is a Node.js application that relies on near-api-js to connect to and interact with the NEAR blockchain. Create accounts, access keys, sign & send transactions with this versatile command line interface tool.

Note: Node.js version 10+ is required to run NEAR CLI.

Release notes

Release notes and unreleased changes can be found in the CHANGELOG

Overview

Click on a command for more information and examples.

Command Description
ACCESS KEYS
near add-credentials Stores credentials for an account locally
near add-key adds a new access key to an account
near delete-key deletes an access key from an account
near generate-key generates a key pair and optionally stores it locally as credentials for an accountId
near list-keys displays all access keys and their details for a given account
near login stores a full access key locally using NEAR Wallet
ACCOUNTS
near create-account creates a new account, either using a faucet to fund it, or an account saved locally
near delete-account deletes an account and transfers remaining balance to a beneficiary account
near list-keys displays all access keys for a given account
near send-near sends tokens from one account to another
near state shows general details of an account
CONTRACTS
near call makes a contract call which can invoke change or view methods
near deploy deploys a smart contract to the NEAR blockchain
near storage Shows the storage state of a given contract, i.e. the data stored in a contract
near view makes a contract call which can only invoke a view method
TRANSACTIONS
near tx-status queries a transaction's status by txHash

[ OPTIONS ]

For EVM support see Project Aurora's aurora-cli.


Setup

Installation

Make sure you have a current version of npm and NodeJS installed.

Mac and Linux

  1. Install npm and node using a package manager like nvm as sometimes there are issues using Ledger due to how OS X handles node packages related to USB devices. [click here]
  2. Ensure you have installed Node version 12 or above.
  3. Install near-cli globally by running:
npm install -g near-cli

Windows

For Windows users, we recommend using Windows Subsystem for Linux (WSL).

  1. Install WSL [click here]
  2. Install npm [click here]
  3. Install Node.js [ click here ]
  4. Change npm default directory [ click here ]
    • This is to avoid any permission issues with WSL
  5. Open WSL and install near-cli globally by running:
npm install -g near-cli

Network selection

The default network for near-cli is testnet.

  • You can change the network by prepending an environment variable to your command.
NEAR_NETWORK=betanet near send ...
  • Alternatively, you can set up a global environment variable by running:
export NEAR_NETWORK=mainnet
  • All commands that interact with the network also allow to pass the --networkId option.
near send-near ... --networkId mainnet

Custom RPC server selection

You can set custom RPC server URL by setting this env variables:

NEAR_MAINNET_RPC
NEAR_TESTNET_RPC

Clear them in case you want to get back to the default RPC server.

Example:

export NEAR_TESTNET_RPC=<put_your_rpc_server_url_here>

Access Keys

All keys are stored locally at the root of your HOME directory:

  • ~/.near-credentials (MAC / Linux)
  • C:\Users\YOUR_ACCOUNT\.near-credentials (Windows)

Inside .near-credentials, access keys are organized in network subdirectories: testnet, and mainnet.

These network subdirectories contain .JSON objects with an:

  • account_id
  • private_key
  • public_key

near add-credentials <accountId>

Stores credentials (full-access-key) locally for an already existing account.

  • arguments: accountId
  • options: --seedPhrase or --secretKey

Examples:

near add-credentials example-acct.testnet --seedPhrase "antique attitude say evolve ring arrive hollow auto wide bronze usual unfold"
near add-credentials example-acct.testnet --secretKey "ed25519:4Ijd3vNUmdWJ4L922BxcsGN1aDrdpvUHEgqLQAUSLmL7S2qE9tYR9fqL6DqabGGDxCSHkKwdaAGNcHJ2Sfd"

near add-key

Adds either a full access or function access key to a given account.

Note: You will use an existing full access key for the account you would like to add a new key to. (near login)

1) add a full access key

  • arguments: accountId publicKey

Example:

near add-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S
Example Response

Adding full access key = Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S to example-acct.testnet.
Transaction Id EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJg
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJg

2) add a function call key

  • arguments: accountId publicKey --contract-id
  • options: --method-names --allowance

accountId is the account you are adding the key to

--contract-id is the contract you are allowing methods to be called on

--method-names are optional and if omitted, all methods of the --contract-id can be called.

--allowance is the amount of Ⓝ the key is allowed to spend on gas fees only (default: 0).

Note: Each transaction made with this key will have gas fees deducted from the initial allowance and once it runs out a new key must be issued.

Example:

near add-key example-acct.testnet GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi --contract-id example-contract.testnet --method-names example_method --allowance 30000000000
Example Response

Adding function call access key = GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi to example-acct.testnet.
Transaction Id H2BQL9fXVmdTbwkXcMFfZ7qhZqC8fFhsA8KDHFdT9q2r
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/H2BQL9fXVmdTbwkXcMFfZ7qhZqC8fFhsA8KDHFdT9q2r


near delete-key

Deletes an existing key for a given account.

  • arguments: accountId publicKey
  • options: --networkId, force

Note: You will need separate full access key for the account you would like to delete a key from. (near login)

Example:

near delete-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S
Example Response

Transaction Id 4PwW7vjzTCno7W433nu4ieA6FvsAjp7zNFwicNLKjQFT
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/4PwW7vjzTCno7W433nu4ieA6FvsAjp7zNFwicNLKjQFT


near generate-key

Displays a key-pair and seed-phrase and optionally stores it locally in .near-credentials.

  • arguments: accountId or none
  • options: --fromSeedPhrase, --saveImplicit

Note: There are several ways to use generate-key that return very different results. Please reference the examples below for further details.


1a) near generate-key

Creates and displays a key pair

near generate-key
Example Response

Seed phrase: antique attitude say evolve ring arrive hollow auto wide bronze usual unfold
Key pair: {"publicKey":"ed25519:BW5Q957u1rTATGpanKUktjVmixEmT56Df4Dt9hoGWEXz","secretKey":"ed25519:5StmPDg9xVNzpyudwxT8Y72iyRq7Fa86hcpsRk6Cq5eWGWqwsPbPT9woXbJs9Qe69crZJHh4DMkrGEPGDDfmXmy2"}
Implicit account: 9c07afc7673ea0f9a20c8a279e8bbe1dd1e283254263bb3b07403e4b6fd7a411


1b) near generate-key --saveImplicit

Creates and displays a key pair, saving it locally in .near-credentials as an implicit account.

near generate-key --saveImplicit
Example Response

Seed phrase: antique attitude say evolve ring arrive hollow auto wide bronze usual unfold
Key pair: {"publicKey":"ed25519:BW5Q957u1rTATGpanKUktjVmixEmT56Df4Dt9hoGWEXz","secretKey":"ed25519:5StmPDg9xVNzpyudwxT8Y72iyRq7Fa86hcpsRk6Cq5eWGWqwsPbPT9woXbJs9Qe69crZJHh4DMkrGEPGDDfmXmy2"}
Implicit account: 9c07afc7673ea0f9a20c8a279e8bbe1dd1e283254263bb3b07403e4b6fd7a411

Storing credentials for account: 9d6e4506ac06ab66a25f6720e400ae26bad40ecbe07d49935e83c7bdba5034fa (network: testnet)
Saving key to '~/.near-credentials/testnet/9d6e4506ac06ab66a25f6720e400ae26bad40ecbe07d49935e83c7bdba5034fa.json'


2) near generate-key accountId

Creates a key pair locally in .near-credentials with an accountId that you specify.

Note: This does NOT create an account with this name.

near generate-key example.testnet
Example Response

Seed phrase: antique attitude say evolve ring arrive hollow auto wide bronze usual unfold
Key pair: {"publicKey":"ed25519:BW5Q957u1rTATGpanKUktjVmixEmT56Df4Dt9hoGWEXz","secretKey":"ed25519:5StmPDg9xVNzpyudwxT8Y72iyRq7Fa86hcpsRk6Cq5eWGWqwsPbPT9woXbJs9Qe69crZJHh4DMkrGEPGDDfmXmy2"}
Implicit account: 9c07afc7673ea0f9a20c8a279e8bbe1dd1e283254263bb3b07403e4b6fd7a411

Storing credentials for account: example.testnet (network: testnet)
Saving key to '~/.near-credentials/testnet/example.testnet.json'


3a) near generate-key --fromSeedPhrase="your seed phrase"

Uses a seed phrase to display a public key and implicit account

near generate-key --seedPhrase="antique attitude say evolve ring arrive hollow auto wide bronze usual unfold"
Example Response
Seed phrase: antique attitude say evolve ring arrive hollow auto wide bronze usual unfold
Key pair: {"publicKey":"ed25519:BW5Q957u1rTATGpanKUktjVmixEmT56Df4Dt9hoGWEXz","secretKey":"ed25519:5StmPDg9xVNzpyudwxT8Y72iyRq7Fa86hcpsRk6Cq5eWGWqwsPbPT9woXbJs9Qe69crZJHh4DMkrGEPGDDfmXmy2"}
Implicit account: 9c07afc7673ea0f9a20c8a279e8bbe1dd1e283254263bb3b07403e4b6fd7a411

3b) near generate-key accountId --seedPhrase="your seed phrase"

Will store the key pair corresponding to the seedPhrase in .near-credentials with an accountId that you specify.


near list-keys

Displays all access keys for a given account.

  • arguments: accountId

Example:

near list-keys client.chainlink.testnet
Example Response

Keys for account client.chainlink.testnet
[
  {
    public_key: 'ed25519:4wrVrZbHrurMYgkcyusfvSJGLburmaw7m3gmCApxgvY4',
    access_key: { nonce: 97, permission: 'FullAccess' }
  },
  {
    public_key: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
    access_key: {
      nonce: 88,
      permission: {
        FunctionCall: {
          allowance: '18483247987345065500000000',
          receiver_id: 'client.chainlink.testnet',
          method_names: [ 'get_token_price', [length]: 1 ]
        }
      }
    }
  },
  [length]: 2
]


near login

locally stores a full access key of an account you created with NEAR Wallet.

  • arguments: none
  • options: --networkId

Example:

near login

Custom wallet url:

Default wallet url is https://testnet.mynearwallet.com/. But if you want to change to a different wallet url, you can setup the environmental variable NEAR_MAINNET_WALLET or NEAR_TESTNET_WALLET.

export NEAR_TESTNET_WALLET=https://wallet.testnet.near.org/
near login

Accounts

near create-account

Creates an account using an existing account or a faucet service to pay for the account's creation and initial balance.

  • arguments: accountId
  • options: --initialBalance, --useFaucet, --useAccount

Examples::

# Creating account using `example-acct.testnet` to fund it
near create-account new-acc.testnet --useAccount example-acct.testnet
# Creating account using the faucet to fund it
near create-account new-acc.testnet --useFaucet

Subaccount example:

near create-account sub-acct.example-acct.testnet --useAccount example-acct.testnet

Example using --initialBalance:

near create-account sub-acct2.example-acct.testnet --useAccount example-acct.testnet --initialBalance 10
Example Response

Saving key to '/HOME_DIR/.near-credentials/default/sub-acct2.example-acct.testnet.json'
Account sub-acct2.example-acct.testnet for network "default" was created.


near delete-account

Deletes an account and transfers remaining balance to a beneficiary account.

  • arguments: accountId beneficiaryId
  • options: force

Example:

near delete-account sub-acct2.example-acct.testnet example-acct.testnet
Example Response

Deleting account. Account id: sub-acct2.example-acct.testnet, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, beneficiary: example-acct.testnet
Transaction Id 4x8xohER1E3yxeYdXPfG8GvXin1ShiaroqE5GdCd5YxX
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/4x8xohER1E3yxeYdXPfG8GvXin1ShiaroqE5GdCd5YxX
Account sub-acct2.example-acct.testnet for network "default" was deleted.


near send-near

Sends NEAR tokens (Ⓝ) from one account to another.

  • arguments: senderId receiverId amount

Note: You will need a full access key for the sending account. (near login)

Example:

near send-near sender.testnet receiver.testnet 10
Example Response

Sending 10 NEAR to receiver.testnet from sender.testnet
Transaction Id BYTr6WNyaEy2ykAiQB9P5VvTyrJcFk6Yw95HPhXC6KfN
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/BYTr6WNyaEy2ykAiQB9P5VvTyrJcFk6Yw95HPhXC6KfN


near state

Shows details of an account's state.

  • arguments: accountId

Example:

near state example.testnet
Example Response

{
    "amount": "99999999303364037168535000",
    "locked": "0",
    "code_hash": "G1PCjeQbvbUsJ8piXNb7Yg6dn3mfivDQN7QkvsVuMt4e",
    "storage_usage": 53528,
    "storage_paid_at": 0,
    "block_height": 21577354,
    "block_hash": "AWu1mrT3eMJLjqyhNHvMKrrbahN6DqcNxXanB5UH1RjB",
    "formattedAmount": "99.999999303364037168535"
}


Contracts

near call

makes a contract call which can modify or view state.

Note: Contract calls require a transaction fee (gas) so you will need an access key for the --accountId that will be charged. (near login)

  • arguments: contractName method_name { args } --accountId
  • options: --gas --deposit

Example:

near call guest-book.testnet addMessage '{"text": "Aloha"}' --account-id example-acct.testnet
Example Response

Scheduling a call: guest-book.testnet.addMessage({"text": "Aloha"})
Transaction Id FY8hBam2iyQfdHkdR1dp6w5XEPJzJSosX1wUeVPyUvVK
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/FY8hBam2iyQfdHkdR1dp6w5XEPJzJSosX1wUeVPyUvVK
''


near deploy

Deploys a smart contract to a given accountId.

  • arguments: accountId .wasmFile
  • options: initFunction initArgs initGas initDeposit

Note: You will need a full access key for the account you are deploying the contract to. (near login)

Example:

near deploy --accountId example-contract.testnet --wasmFile out/example.wasm

Initialize Example:

near deploy --accountId example-contract.testnet --wasmFile out/example.wasm --initFunction new --initArgs '{"owner_id": "example-contract.testnet", "total_supply": "10000000"}'
Example Response

Starting deployment. Account id: example-contract.testnet, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: main.wasm
Transaction Id G8GhhPuujMHTRnwursPXE1Lv5iUZ8WUecwiST1PcKWMt
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/G8GhhPuujMHTRnwursPXE1Lv5iUZ8WUecwiST1PcKWMt
Done deploying to example-contract.testnet


near storage

Shows the storage state of a given contract, i.e. the data stored in a contract.

  • arguments: contractName
  • options: --finality, --utf8, --blockId, --prefix

Example:

near storage hello.near-examples.testnet --finality optimistic --utf8
Example Response
[ { key: 'STATE', value: '\x10\x00\x00\x00Passei por aqui!' } ]

near view

Makes a contract call which can only view state. (Call is free of charge)

  • arguments: contractName method_name { args }
  • options: default

Example:

near view guest-book.testnet getMessages '{}'
Example Response

View call: guest-book.testnet.getMessages({})
[
  { premium: false, sender: 'waverlymaven.testnet', text: 'TGIF' },
  {
    premium: true,
    sender: 'waverlymaven.testnet',
    text: 'Hello from New York 🌈'
  },
  { premium: false, sender: 'fhr.testnet', text: 'Hi' },
  { premium: true, sender: 'eugenethedream', text: 'test' },
  { premium: false, sender: 'dongri.testnet', text: 'test' },
  { premium: false, sender: 'dongri.testnet', text: 'hello' },
  { premium: true, sender: 'dongri.testnet', text: 'hey' },
  { premium: false, sender: 'hirokihori.testnet', text: 'hello' },
  { premium: true, sender: 'eugenethedream', text: 'hello' },
  { premium: false, sender: 'example-acct.testnet', text: 'Aloha' },
  [length]: 10
]


Transactions

near tx-status

Queries transaction status by hash and accountId.

  • arguments: txHash --accountId
  • options: default

Example:

near tx-status FY8hBam2iyQfdHkdR1dp6w5XEPJzJSosX1wUeVPyUvVK --accountId guest-book.testnet
Example Response

Transaction guest-book.testnet:FY8hBam2iyQfdHkdR1dp6w5XEPJzJSosX1wUeVPyUvVK
{
  status: { SuccessValue: '' },
  transaction: {
    signer_id: 'example-acct.testnet',
    public_key: 'ed25519:AXZZKnp6ZcWXyRNdy8FztYrniKf1qt6YZw6mCCReXrDB',
    nonce: 20,
    receiver_id: 'guest-book.testnet',
    actions: [
      {
        FunctionCall: {
          method_name: 'addMessage',
          args: 'eyJ0ZXh0IjoiQWxvaGEifQ==',
          gas: 300000000000000,
          deposit: '0'
        }
      },
      [length]: 1
    ],
    signature: 'ed25519:5S6nZXPU72nzgAsTQLmAFfdVSykdKHWhtPMb5U7duacfPdUjrj8ipJxuRiWkZ4yDodvDNt92wcHLJxGLsyNEsZNB',
    hash: 'FY8hBam2iyQfdHkdR1dp6w5XEPJzJSosX1wUeVPyUvVK'
  },
  transaction_outcome: {
    proof: [ [length]: 0 ],
    block_hash: '6nsjvzt6C52SSuJ8UvfaXTsdrUwcx8JtHfnUj8XjdKy1',
    id: 'FY8hBam2iyQfdHkdR1dp6w5XEPJzJSosX1wUeVPyUvVK',
    outcome: {
      logs: [ [length]: 0 ],
      receipt_ids: [ '7n6wjMgpoBTp22ScLHxeMLzcCvN8Vf5FUuC9PMmCX6yU', [length]: 1 ],
      gas_burnt: 2427979134284,
      tokens_burnt: '242797913428400000000',
      executor_id: 'example-acct.testnet',
      status: {
        SuccessReceiptId: '7n6wjMgpoBTp22ScLHxeMLzcCvN8Vf5FUuC9PMmCX6yU'
      }
    }
  },
  receipts_outcome: [
    {
      proof: [ [length]: 0 ],
      block_hash: 'At6QMrBuFQYgEPAh6fuRBmrTAe9hXTY1NzAB5VxTH1J2',
      id: '7n6wjMgpoBTp22ScLHxeMLzcCvN8Vf5FUuC9PMmCX6yU',
      outcome: {
        logs: [ [length]: 0 ],
        receipt_ids: [ 'FUttfoM2odAhKNQrJ8F4tiBpQJPYu66NzFbxRKii294e', [length]: 1 ],
        gas_burnt: 3559403233496,
        tokens_burnt: '355940323349600000000',
        executor_id: 'guest-book.testnet',
        status: { SuccessValue: '' }
      }
    },
    {
      proof: [ [length]: 0 ],
      block_hash: 'J7KjpMPzAqE7iX82FAQT3qERDs6UR1EAqBLPJXBzoLCk',
      id: 'FUttfoM2odAhKNQrJ8F4tiBpQJPYu66NzFbxRKii294e',
      outcome: {
        logs: [ [length]: 0 ],
        receipt_ids: [ [length]: 0 ],
        gas_burnt: 0,
        tokens_burnt: '0',
        executor_id: 'example-acct.testnet',
        status: { SuccessValue: '' }
      }
    },
    [length]: 2
  ]
}


Validators

near validators current

Displays details of current validators.

  • amount staked
  • number of seats
  • percentage of uptime
  • expected block production
  • blocks actually produced
  • arguments: current
  • options: default

Example:

near validators current

Example for mainnet:

NEAR_ENV=mainnet near validators current
Example Response

Validators (total: 49, seat price: 1,976,588):
.--------------------------------------------------------------------------------------------------------------------.
| Validator Id                                 | Stake      | Seats | % Online | Blocks produced | Blocks expected |
|----------------------------------------------|------------|-------|----------|-----------------|-----------------|
| cryptium.poolv1.near                         | 13,945,727 | 7     | 100%     | 1143            | 1143            |
| astro-stakers.poolv1.near                    | 11,660,189 | 5     | 100%     | 817             | 817             |
| blockdaemon.poolv1.near                      | 11,542,867 | 5     | 76.74%   | 627             | 817             |
| zavodil.poolv1.near                          | 11,183,187 | 5     | 100%     | 818             | 818             |
| bisontrails.poolv1.near                      | 10,291,696 | 5     | 99.38%   | 810             | 815             |
| dokiacapital.poolv1.near                     | 7,906,352  | 3     | 99.54%   | 650             | 653             |
| chorusone.poolv1.near                        | 7,480,508  | 3     | 100%     | 490             | 490             |
| figment.poolv1.near                          | 6,931,070  | 3     | 100%     | 489             | 489             |
| stardust.poolv1.near                         | 6,401,678  | 3     | 100%     | 491             | 491             |
| anonymous.poolv1.near                        | 6,291,821  | 3     | 97.55%   | 479             | 491             |
| d1.poolv1.near                               | 6,265,109  | 3     | 100%     | 491             | 491             |
| near8888.poolv1.near                         | 6,202,968  | 3     | 99.38%   | 486             | 489             |
| rekt.poolv1.near                             | 5,950,212  | 3     | 100%     | 490             | 490             |
| epic.poolv1.near                             | 5,639,256  | 2     | 100%     | 326             | 326             |
| fresh.poolv1.near                            | 5,460,410  | 2     | 100%     | 327             | 327             |
| buildlinks.poolv1.near                       | 4,838,398  | 2     | 99.38%   | 325             | 327             |
| jubi.poolv1.near                             | 4,805,921  | 2     | 100%     | 326             | 326             |
| openshards.poolv1.near                       | 4,644,553  | 2     | 100%     | 326             | 326             |
| jazza.poolv1.near                            | 4,563,432  | 2     | 100%     | 327             | 327             |
| northernlights.poolv1.near                   | 4,467,978  | 2     | 99.39%   | 326             | 328             |
| inotel.poolv1.near                           | 4,427,152  | 2     | 100%     | 327             | 327             |
| baziliknear.poolv1.near                      | 4,261,142  | 2     | 100%     | 328             | 328             |
| stakesabai.poolv1.near                       | 4,242,618  | 2     | 100%     | 326             | 326             |
| everstake.poolv1.near                        | 4,234,552  | 2     | 100%     | 327             | 327             |
| stakin.poolv1.near                           | 4,071,704  | 2     | 100%     | 327             | 327             |
| certusone.poolv1.near                        | 3,734,505  | 1     | 100%     | 164             | 164             |
| lux.poolv1.near                              | 3,705,394  | 1     | 100%     | 163             | 163             |
| staked.poolv1.near                           | 3,683,365  | 1     | 100%     | 164             | 164             |
| lunanova.poolv1.near                         | 3,597,231  | 1     | 100%     | 163             | 163             |
| appload.poolv1.near                          | 3,133,163  | 1     | 100%     | 163             | 163             |
| smart-stake.poolv1.near                      | 3,095,711  | 1     | 100%     | 164             | 164             |
| artemis.poolv1.near                          | 3,009,462  | 1     | 99.39%   | 163             | 164             |
| moonlet.poolv1.near                          | 2,790,296  | 1     | 100%     | 163             | 163             |
| nearfans.poolv1.near                         | 2,771,137  | 1     | 100%     | 163             | 163             |
| nodeasy.poolv1.near                          | 2,692,745  | 1     | 99.39%   | 163             | 164             |
| erm.poolv1.near                              | 2,653,524  | 1     | 100%     | 164             | 164             |
| zkv_staketosupportprivacy.poolv1.near        | 2,548,343  | 1     | 99.39%   | 163             | 164             |
| dsrvlabs.poolv1.near                         | 2,542,925  | 1     | 100%     | 164             | 164             |
| 08investinwomen_runbybisontrails.poolv1.near | 2,493,123  | 1     | 100%     | 163             | 163             |
| electric.poolv1.near                         | 2,400,532  | 1     | 99.39%   | 163             | 164             |
| sparkpool.poolv1.near                        | 2,378,191  | 1     | 100%     | 163             | 163             |
| hashquark.poolv1.near                        | 2,376,424  | 1     | 100%     | 164             | 164             |
| masternode24.poolv1.near                     | 2,355,634  | 1     | 100%     | 164             | 164             |
| sharpdarts.poolv1.near                       | 2,332,398  | 1     | 99.38%   | 162             | 163             |
| fish.poolv1.near                             | 2,315,249  | 1     | 100%     | 163             | 163             |
| ashert.poolv1.near                           | 2,103,327  | 1     | 97.56%   | 160             | 164             |
| 01node.poolv1.near                           | 2,058,200  | 1     | 100%     | 163             | 163             |
| finoa.poolv1.near                            | 2,012,304  | 1     | 100%     | 163             | 163             |
| majlovesreg.poolv1.near                      | 2,005,032  | 1     | 100%     | 164             | 164             |
'--------------------------------------------------------------------------------------------------------------------'


near validators next

Displays details for the next round of validators.

  • total number of seats available
  • seat price
  • amount staked
  • number of seats assigned per validator
  • arguments: next
  • options: default

Example:

near validators next

Example for mainnet:

NEAR_ENV=mainnet near validators next
Example Response

Next validators (total: 49, seat price: 1,983,932):
.----------------------------------------------------------------------------------------------.
| Status   | Validator                                    | Stake                    | Seats |
|----------|----------------------------------------------|--------------------------|-------|
| Rewarded | cryptium.poolv1.near                         | 13,945,727 -> 14,048,816 | 7     |
| Rewarded | astro-stakers.poolv1.near                    | 11,660,189 -> 11,704,904 | 5     |
| Rewarded | blockdaemon.poolv1.near                      | 11,542,867 -> 11,545,942 | 5     |
| Rewarded | zavodil.poolv1.near                          | 11,183,187 -> 11,204,123 | 5     |
| Rewarded | bisontrails.poolv1.near                      | 10,291,696 -> 10,297,923 | 5     |
| Rewarded | dokiacapital.poolv1.near                     | 7,906,352 -> 8,097,275   | 4     |
| Rewarded | chorusone.poolv1.near                        | 7,480,508 -> 7,500,576   | 3     |
| Rewarded | figment.poolv1.near                          | 6,931,070 -> 6,932,916   | 3     |
| Rewarded | stardust.poolv1.near                         | 6,401,678 -> 6,449,363   | 3     |
| Rewarded | anonymous.poolv1.near                        | 6,291,821 -> 6,293,497   | 3     |
| Rewarded | d1.poolv1.near                               | 6,265,109 -> 6,266,777   | 3     |
| Rewarded | near8888.poolv1.near                         | 6,202,968 -> 6,204,620   | 3     |
| Rewarded | rekt.poolv1.near                             | 5,950,212 -> 5,951,797   | 2     |
| Rewarded | epic.poolv1.near                             | 5,639,256 -> 5,640,758   | 2     |
| Rewarded | fresh.poolv1.near                            | 5,460,410 -> 5,461,811   | 2     |
| Rewarded | buildlinks.poolv1.near                       | 4,838,398 -> 4,839,686   | 2     |
| Rewarded | jubi.poolv1.near                             | 4,805,921 -> 4,807,201   | 2     |
| Rewarded | openshards.poolv1.near                       | 4,644,553 -> 4,776,692   | 2     |
| Rewarded | jazza.poolv1.near                            | 4,563,432 -> 4,564,648   | 2     |
| Rewarded | northernlights.poolv1.near                   | 4,467,978 -> 4,469,168   | 2     |
| Rewarded | inotel.poolv1.near                           | 4,427,152 -> 4,428,331   | 2     |
| Rewarded | baziliknear.poolv1.near                      | 4,261,142 -> 4,290,338   | 2     |
| Rewarded | stakesabai.poolv1.near                       | 4,242,618 -> 4,243,748   | 2     |
| Rewarded | everstake.poolv1.near                        | 4,234,552 -> 4,235,679   | 2     |
| Rewarded | stakin.poolv1.near                           | 4,071,704 -> 4,072,773   | 2     |
| Rewarded | certusone.poolv1.near                        | 3,734,505 -> 3,735,500   | 1     |
| Rewarded | lux.poolv1.near                              | 3,705,394 -> 3,716,381   | 1     |
| Rewarded | staked.poolv1.near                           | 3,683,365 -> 3,684,346   | 1     |
| Rewarded | lunanova.poolv1.near                         | 3,597,231 -> 3,597,836   | 1     |
| Rewarded | appload.poolv1.near                          | 3,133,163 -> 3,152,302   | 1     |
| Rewarded | smart-stake.poolv1.near                      | 3,095,711 -> 3,096,509   | 1     |
| Rewarded | artemis.poolv1.near                          | 3,009,462 -> 3,010,265   | 1     |
| Rewarded | moonlet.poolv1.near                          | 2,790,296 -> 2,948,565   | 1     |
| Rewarded | nearfans.poolv1.near                         | 2,771,137 -> 2,771,875   | 1     |
| Rewarded | nodeasy.poolv1.near                          | 2,692,745 -> 2,693,463   | 1     |
| Rewarded | erm.poolv1.near                              | 2,653,524 -> 2,654,231   | 1     |
| Rewarded | dsrvlabs.poolv1.near                         | 2,542,925 -> 2,571,865   | 1     |
| Rewarded | zkv_staketosupportprivacy.poolv1.near        | 2,548,343 -> 2,549,022   | 1     |
| Rewarded | 08investinwomen_runbybisontrails.poolv1.near | 2,493,123 -> 2,493,787   | 1     |
| Rewarded | masternode24.poolv1.near                     | 2,355,634 -> 2,456,226   | 1     |
| Rewarded | fish.poolv1.near                             | 2,315,249 -> 2,415,831   | 1     |
| Rewarded | electric.poolv1.near                         | 2,400,532 -> 2,401,172   | 1     |
| Rewarded | sparkpool.poolv1.near                        | 2,378,191 -> 2,378,824   | 1     |
| Rewarded | hashquark.poolv1.near                        | 2,376,424 -> 2,377,057   | 1     |
| Rewarded | sharpdarts.poolv1.near                       | 2,332,398 -> 2,332,948   | 1     |
| Rewarded | ashert.poolv1.near                           | 2,103,327 -> 2,103,887   | 1     |
| Rewarded | 01node.poolv1.near                           | 2,058,200 -> 2,058,760   | 1     |
| Rewarded | finoa.poolv1.near                            | 2,012,304 -> 2,015,808   | 1     |
| Rewarded | majlovesreg.poolv1.near                      | 2,005,032 -> 2,005,566   | 1     |
'----------------------------------------------------------------------------------------------'


near proposals

Displays validator proposals for epoch after next.

  • expected seat price
  • status of proposals
  • previous amount staked and new amount that will be staked
  • amount of seats assigned per validator
  • arguments: none
  • options: default

Example:

near proposals

Example for mainnet:

NEAR_ENV=mainnet near proposals
Example Response

Proposals for the epoch after next (new: 51, passing: 49, expected seat price = 1,983,932)
.--------------------------------------------------------------------------------------------------------.
| Status             | Validator                                    | Stake => New Stake       | Seats |
|--------------------|----------------------------------------------|--------------------------|-------|
| Proposal(Accepted) | cryptium.poolv1.near                         | 13,945,727 => 14,041,766 | 7     |
| Proposal(Accepted) | astro-stakers.poolv1.near                    | 11,660,189 => 11,705,673 | 5     |
| Proposal(Accepted) | blockdaemon.poolv1.near                      | 11,542,867 => 11,545,942 | 5     |
| Proposal(Accepted) | zavodil.poolv1.near                          | 11,183,187 => 11,207,805 | 5     |
| Proposal(Accepted) | bisontrails.poolv1.near                      | 10,291,696 => 10,300,978 | 5     |
| Proposal(Accepted) | dokiacapital.poolv1.near                     | 7,906,352 => 8,097,275   | 4     |
| Proposal(Accepted) | chorusone.poolv1.near                        | 7,480,508 => 7,568,268   | 3     |
| Proposal(Accepted) | figment.poolv1.near                          | 6,931,070 => 6,932,916   | 3     |
| Proposal(Accepted) | stardust.poolv1.near                         | 6,401,678 => 6,449,363   | 3     |
| Proposal(Accepted) | anonymous.poolv1.near                        | 6,291,821 => 6,293,497   | 3     |
| Proposal(Accepted) | d1.poolv1.near                               | 6,265,109 => 6,266,777   | 3     |
| Proposal(Accepted) | near8888.poolv1.near                         | 6,202,968 => 6,204,620   | 3     |
| Proposal(Accepted) | rekt.poolv1.near                             | 5,950,212 => 5,951,797   | 2     |
| Proposal(Accepted) | epic.poolv1.near                             | 5,639,256 => 5,640,758   | 2     |
| Proposal(Accepted) | fresh.poolv1.near                            | 5,460,410 => 5,461,811   | 2     |
| Proposal(Accepted) | buildlinks.poolv1.near                       | 4,838,398 => 4,839,686   | 2     |
| Proposal(Accepted) | jubi.poolv1.near                             | 4,805,921 => 4,807,201   | 2     |
| Proposal(Accepted) | openshards.poolv1.near                       | 4,644,553 => 4,776,692   | 2     |
| Proposal(Accepted) | jazza.poolv1.near                            | 4,563,432 => 4,564,648   | 2     |
| Proposal(Accepted) | northernlights.poolv1.near                   | 4,467,978 => 4,469,168   | 2     |
| Proposal(Accepted) | inotel.poolv1.near                           | 4,427,152 => 4,428,331   | 2     |
| Proposal(Accepted) | baziliknear.poolv1.near                      | 4,261,142 => 4,290,891   | 2     |
| Proposal(Accepted) | stakesabai.poolv1.near                       | 4,242,618 => 4,243,748   | 2     |
| Proposal(Accepted) | everstake.poolv1.near                        | 4,234,552 => 4,235,679   | 2     |
| Proposal(Accepted) | stakin.poolv1.near                           | 4,071,704 => 4,072,773   | 2     |
| Proposal(Accepted) | certusone.poolv1.near                        | 3,734,505 => 3,735,500   | 1     |
| Proposal(Accepted) | lux.poolv1.near                              | 3,705,394 => 3,716,381   | 1     |
| Proposal(Accepted) | staked.poolv1.near                           | 3,683,365 => 3,684,346   | 1     |
| Proposal(Accepted) | lunanova.poolv1.near                         | 3,597,231 => 3,597,836   | 1     |
| Proposal(Accepted) | appload.poolv1.near                          | 3,133,163 => 3,152,302   | 1     |
| Proposal(Accepted) | smart-stake.poolv1.near                      | 3,095,711 => 3,096,509   | 1     |
| Proposal(Accepted) | artemis.poolv1.near                          | 3,009,462 => 3,010,265   | 1     |
| Proposal(Accepted) | moonlet.poolv1.near                          | 2,790,296 => 2,948,565   | 1     |
| Proposal(Accepted) | nearfans.poolv1.near                         | 2,771,137 => 2,771,875   | 1     |
| Proposal(Accepted) | nodeasy.poolv1.near                          | 2,692,745 => 2,693,463   | 1     |
| Proposal(Accepted) | erm.poolv1.near                              | 2,653,524 => 2,654,231   | 1     |
| Proposal(Accepted) | dsrvlabs.poolv1.near                         | 2,542,925 => 2,571,865   | 1     |
| Proposal(Accepted) | zkv_staketosupportprivacy.poolv1.near        | 2,548,343 => 2,549,022   | 1     |
| Proposal(Accepted) | 08investinwomen_runbybisontrails.poolv1.near | 2,493,123 => 2,493,787   | 1     |
| Proposal(Accepted) | masternode24.poolv1.near                     | 2,355,634 => 2,456,226   | 1     |
| Proposal(Accepted) | fish.poolv1.near                             | 2,315,249 => 2,415,831   | 1     |
| Proposal(Accepted) | electric.poolv1.near                         | 2,400,532 => 2,401,172   | 1     |
| Proposal(Accepted) | sparkpool.poolv1.near                        | 2,378,191 => 2,378,824   | 1     |
| Proposal(Accepted) | hashquark.poolv1.near                        | 2,376,424 => 2,377,057   | 1     |
| Proposal(Accepted) | sharpdarts.poolv1.near                       | 2,332,398 => 2,332,948   | 1     |
| Proposal(Accepted) | ashert.poolv1.near                           | 2,103,327 => 2,103,887   | 1     |
| Proposal(Accepted) | 01node.poolv1.near                           | 2,058,200 => 2,059,314   | 1     |
| Proposal(Accepted) | finoa.poolv1.near                            | 2,012,304 => 2,015,808   | 1     |
| Proposal(Accepted) | majlovesreg.poolv1.near                      | 2,005,032 => 2,005,566   | 1     |
| Proposal(Declined) | huobipool.poolv1.near                        | 1,666,976                | 0     |
| Proposal(Declined) | hb436_pool.poolv1.near                       | 500,030                  | 0     |
'--------------------------------------------------------------------------------------------------------'


JS Contracts Enclave

near js

You can use near js <command> <args> to be able to interact with JS enclaved contracts. Run near js --help for instructions. An optional --jsvm <accountId> argument can be supplied to the following js subcommands to point to a different JSVM enclave contract. The default is set to jsvm.testnet and jsvm.near respectively for testnet and mainnet. Note that anything changing state in the enclave will require a deposit to maintain storage of either the contract bytes or the state of the contract itself.

near js deploy

Deploys a smart contract to a given accountId on the JSVM enclave.

  • arguments: accountId, base64File, deposit
  • options: jsvm

Note: You will need a full access key for the account you are deploying the contract to. (near login)

Example:

near deploy --accountId example-contract.testnet --base64File out/example.base64 --deposit 0.1
Example Response

Starting deployment. Account id: example-contract.testnet, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: out/example.base64, JSVM: jsvm.testnet
Transaction Id 4Nxsszgh2LaXPZph37peZKDqPZeJEErPih6n4jWcGDEB
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/4Nxsszgh2LaXPZph37peZKDqPZeJEErPih6n4jWcGDEB
Done deploying to example-contract.testnet

near js dev-deploy

Creates a development account and deploys a smart contract to the enclave associated to the dev-account. No access keys needed. (testnet only)

  • arguments: base64File deposit
  • options: jsvm

Example:

near js dev-deploy --base64File out/example.base64 --deposit 0.1
Example Response

Starting deployment. Account id: dev-1653005231830-15694723179173, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: out/example.base64, JSVM: jsvm.testnet
Transaction Id FTVd4TKzy9mrmWvok6qHaoX68cVZnUJp2VqUgH6Y446n
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/FTVd4TKzy9mrmWvok6qHaoX68cVZnUJp2VqUgH6Y446n
Done deploying to dev-1653005231830-15694723179173

near js call

makes a contract call which can modify or view state into the JSVM enclase

Note: Contract calls require a transaction fee (gas) so you will need an access key for the --accountId that will be charged. (near login)

  • arguments: contractName methodName { args } --accountId --deposit
  • options: --gas --jsvm

Example:

near js call dev-1653005231830-15694723179173 set_status '["hello world"]' --deposit 0.1 --account-id dev-1653005231830-15694723179173
Example Response

Scheduling a call in JSVM[jsvm.testnet]: dev-1653005231830-15694723179173.set_status(["hello world"]) with attached 0.1 NEAR
Receipts: 5QUuNwSYrDcEPKuSnU7fKN7YCGfXmdmZR9m3zUSTek7P, 3YU4eFhqBruc4z8KKLZr1U1oY31A6Bfks45GLA2rq5GS
  Log [jsvm.testnet]: dev-1653005231830-15694723179173 set_status with message hello world
Transaction Id sP8s9REgK9YcZzkudyccg8R968zYWDVGCNv4wxeZsUe
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/sP8s9REgK9YcZzkudyccg8R968zYWDVGCNv4wxeZsUe
''

near js view

Makes a contract call which can only view state. (Call is free of charge and does not require deposit)

  • arguments: contractName method_name { args }
  • options: jsvm

Example:

near js view dev-1653005231830-15694723179173 get_status '["dev-1653005231830-15694723179173"]' --accountId dev-1653005231830-15694723179173
Example Response

View call in JSVM[jsvm.testnet]: dev-1653005231830-15694723179173.get_status(["dev-1653005231830-15694723179173"])
Log [jsvm.testnet]: get_status for account_id dev-1653005231830-15694723179173
'hello world'

near js remove

Removes the contract on the JS enclase and refunds all the deposit to the actual account.

  • arguments: accountId
  • options: jsvm
near js remove --accountId dev-1653005231830-15694723179173
Example Response

Removing contract from enclave. Account id: dev-1653005231830-15694723179173, JSVM: jsvm.testnet
Transaction Id FGSfvoWmhS1fWb6ckpPMYvc7seNaGQ5MU7iSrY43ZWiG
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/FGSfvoWmhS1fWb6ckpPMYvc7seNaGQ5MU7iSrY43ZWiG

REPL

near repl

Launches NEAR REPL (an interactive JavaScript programming invironment) connected to NEAR.

  • arguments: none
  • options: --accountId, --script

To launch, run:

near repl
  • You will then be shown a prompt > and can begin interacting with NEAR.
  • Try typing the following into your prompt that converts NEAR (Ⓝ) into yoctoNEAR (10^-24):
nearAPI.utils.format.parseNearAmount('1000')

You can also use an --accountId with near repl.

The script argument allows you to pass the path to a javascript/typescript file that exports a main function taking a Context as an argument. Anything passed after -- is passed to the script as the argv argument.

Note: you will need to add near-cli as a dependency in order to import the types.

e.g.

import { Context } from "near-cli/context";

Example:

near repl --accountId example-acct.testnet
  • Then try console logging account after the > prompt.
> console.log(account)

Or in a JS files

near repl --accountId example-acct.testnet --script print_account.js
module.exports.main = async function main({account, near, nearAPI, argv}) {
    console.log(account);
}

or TS

near repl --accountId example-acct.testnet --script print_account.ts
import { Context } from "near-cli/context"

export async function main({account, near, nearAPI, argv}: Context) {
    console.log(account);
}
Example Response

Account {
  accessKeyByPublicKeyCache: {},
  connection: Connection {
    networkId: 'default',
    provider: JsonRpcProvider { connection: [Object] },
    signer: InMemorySigner { keyStore: [MergeKeyStore] }
  },
  accountId: 'example-acct.testnet',
  _ready: Promise { undefined },
  _state: {
    amount: '98786165075093615800000000',
    locked: '0',
    code_hash: '11111111111111111111111111111111',
    storage_usage: 741,
    storage_paid_at: 0,
    block_height: 21661252,
    block_hash: 'HbAj25dTzP3ssYjNRHov9BQ72UxpHGVqZK1mZwGdGNbo'
  }
}

You can also get a private key's public key.

  • First, declare a privateKey variable:
const myPrivateKey =
    "3fKM9Rr7LHyzhhzmmedXLvc59rayfh1oUYS3VfUcxwpAFQZtdx1G9aTY6i8hG9mQtYoycTEFTBtatgNKHRtYamrS";
  • Then run:
nearAPI.KeyPair.fromString(myPrivateKey).publicKey.toString();

With NEAR REPL you have complete access to near-api-js to help you develop on the NEAR platform.


Options

Option Description
--help Show help [boolean]
--version Show version number [boolean]
--nodeUrl, --node_url NEAR node URL [string] [default: "https://rpc.testnet.near.org"]
--networkId, --network_id NEAR network ID, allows using different keys based on network [string] [default: "testnet"]
--helperUrl NEAR contract helper URL [string]
--keyPath Path to master account key [string]
--accountId, --account_id Unique identifier for the account [string]
--useLedgerKey Use Ledger for signing with given HD key path [string] [default: "44'/397'/0'/0'/1'"]
--seedPhrase Seed phrase mnemonic [string]
--seedPath HD path derivation [string] [default: "m/44'/397'/0'"]
--walletUrl Website for NEAR Wallet [string]
--contractName Account name of contract [string]
--masterAccount Master account used when creating new accounts [string]
--helperAccount Expected top-level account for a network [string]
-v, --verbose Prints out verbose output [boolean] [default: false]
-f, --force Forcefully execute the desired action even if it is unsafe to do so [boolean] [default: false]

Got a question? Ask it on StackOverflow!

License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE and LICENSE-APACHE for details.