#near #command-line #helps #interact #human-friendly #protocols #companion

bin+lib near-cli-rs

human-friendly console utility that helps to interact with NEAR Protocol from command line

47 releases (15 breaking)

new 0.17.0 Dec 17, 2024
0.16.0 Nov 19, 2024
0.13.0 Jul 30, 2024
0.8.1 Feb 26, 2024
0.2.1 Dec 20, 2022

#67 in Magic Beans

Download history 597/week @ 2024-08-26 1311/week @ 2024-09-02 772/week @ 2024-09-09 529/week @ 2024-09-16 502/week @ 2024-09-23 434/week @ 2024-09-30 353/week @ 2024-10-07 596/week @ 2024-10-14 378/week @ 2024-10-21 379/week @ 2024-10-28 300/week @ 2024-11-04 321/week @ 2024-11-11 565/week @ 2024-11-18 173/week @ 2024-11-25 502/week @ 2024-12-02 740/week @ 2024-12-09

2,010 downloads per month
Used in 4 crates (3 directly)

MIT/Apache and maybe GPL-3.0-or-later

1MB
21K SLoC

NEAR CLI

near CLI is your human-friendly companion that helps to interact with NEAR Protocol from command line.

Just run near and let it guide you through!

Install

Visit Releases page to see the latest updates.

Install via Windows Installer (Windows)

https://github.com/user-attachments/assets/607f797b-0412-4741-984b-6b6032d05262

Install via powershell script (Windows)
irm https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.ps1 | iex

https://github.com/user-attachments/assets/7d5d090e-4885-4c27-9d0f-045905952071

Install via shell script (macOS, Linux, Windows/WSL)
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh
Run via npx (Node.js on Windows, Linux, macOS)
npx near-cli-rs
Use in package.json scripts (Node.js on Windows, Linux, macOS)
npm install near-cli-rs
Get a portable version (Windows, Linux, macOS)

https://github.com/user-attachments/assets/4a7e4633-1957-4dc2-a032-827fa9c06c29

Compile and install from the source code (Cargo on Windows, Linux, macOS)

Install it with cargo, just make sure you have Rust installed on your computer.

cargo install near-cli-rs

or, install the most recent version from git repository:

$ cargo install --git https://github.com/near/near-cli-rs
Install on CI (GitHub Actions)

It is often desirable to use near CLI from CI to automate some actions, so here is an example of how you can make a function call during CI:

name: Release
on:
  push:
    branches: [main]

jobs:
  deploy-widgets:
    runs-on: ubuntu-latest
    name: Make a function call on mainnet
    env:
      NEAR_NETWORK_CONNECTION: mainnet
      NEAR_CONTRACT_ACCOUNT_ID: ${{ vars.NEAR_CONTRACT_ACCOUNT_ID }}
      NEAR_SIGNER_ACCOUNT_ID: ${{ vars.NEAR_SIGNER_ACCOUNT_ID }}
      NEAR_SIGNER_ACCOUNT_PUBLIC_KEY: ${{ vars.NEAR_SIGNER_ACCOUNT_PUBLIC_KEY }}
      NEAR_SIGNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.NEAR_SIGNER_ACCOUNT_PRIVATE_KEY }}

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Install near CLI
      run: |
        curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.7.4/near-cli-rs-installer.sh | sh

    - name: Call some function
      run: |
        near contract call-function as-transaction "$NEAR_CONTRACT_ACCOUNT_ID" 'function_name_here' json-args '{}' prepaid-gas '100 TeraGas' attached-deposit '0 NEAR' sign-as "$NEAR_SIGNER_ACCOUNT_ID" network-config "$NEAR_NETWORK_CONNECTION" sign-with-plaintext-private-key --signer-public-key "$NEAR_SIGNER_ACCOUNT_PUBLIC_KEY" --signer-private-key "$NEAR_SIGNER_ACCOUNT_PRIVATE_KEY" send

You will need to configure GitHub Actions Secrets and Variables and once it is ready, this CI will only take a couple of seconds to complete!

See how it is used by DevHub.

Run

Once installed, you just run it with near command:

$ near

? What are you up to? (select one of the options with the up-down arrows on your keyboard and press Enter)
> account     - Manage accounts
  tokens      - Manage token assets such as NEAR, FT, NFT
  staking     - Manage staking: view, add and withdraw stake
  contract    - Manage smart-contracts: deploy code, call functions
  transaction - Operate transactions
  config      - Manage connections in a configuration file (config.toml)
  extension   - Manage near CLI and extensions
[↑↓ to move, enter to select, type to filter]

The CLI interactively guides you through some pretty complex topics, helping you make informed decisions along the way. Also, you can enable shell history integration

Read more in English

Больше информации на русском языке (in Russian)

Dependencies

~48–70MB
~1M SLoC