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

fix: added message for Ledger users #1111

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
## [unreleased]
- ...

## `4.0.12` [03-19-2024]
- New: Added back Ledger support, please notice that the `--useLedger` does not set the path anymore, use `--ledgerPath` for this.
- New: Added back all `validator` commands.
- New: Added `add-credentials` command to add credentials to the `near-cli` config file.
- Fixes: Multitude of small fixes, see each release note for more details.

## `4.0.0` [01-23-2024]
- Reorganized code to simplify its maintenance.
- New: Fixed `create-account` can now create `TLA`, `sub-accounts` and `.testnet/.near` accounts.
Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# NEAR CLI (command line interface)

[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/near/near-cli)

NEAR CLI is a Node.js application that relies on [`near-api-js`](https://github.com/near/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 16+ is required to run NEAR CLI.

## 🚨 v4.0.0 Notes
This release is a major reorganization of the codebase to simplify its maintenance. It also includes a few new features and a multitude of small fixes.

The most notable changes are:
- **Ledger users**, please notice that the `--useLedger` does not set the path anymore, use `--ledgerPath` for this
- Please check the commands that support Ledger for more details
- Users can now import credentials using the `add-credentials` command
- The `generate-key` command now has a `--saveImplicit` option to save the key as an implicit account
- Users can create `testnet` pre-funded accounts using the `--useFaucet` option
- Accounts cannot create `TLA` with less than 32 characters anymore (this is a NEAR protocol change)
- Removed unnecessary options from commands, e.g. `view` now does not take an `--accountId` or `--masterAccount`
- If a command does not work, please first check the commands help to see if the options have changed
- For example, run `near create-account` to see how options might have changed

## Release notes

**Release notes and unreleased changes can be found in the [CHANGELOG](CHANGELOG.md)**
Release notes and unreleased changes can be found in the [CHANGELOG](CHANGELOG.md)

## Overview

Expand Down Expand Up @@ -37,7 +49,6 @@ _Click on a command for more information and examples._
| **TRANSACTIONS** | |
| [`near tx-status`](#near-tx-status) | queries a transaction's status by `txHash` |


---

## Setup
Expand Down Expand Up @@ -111,6 +122,9 @@ export NEAR_NETWORK=mainnet
near send-near ... --networkId mainnet
```

> [!WARNING]
> In previous versions, `near-cli` used `NEAR_ENV` to set the network. This can still be used, but `NEAR_NETWORK` has priority over `NEAR_ENV` if both are set.

---

### Custom RPC server selection
Expand All @@ -123,7 +137,7 @@ Clear them in case you want to get back to the default RPC server.

Example:
```bash
export NEAR_TESTNET_RPC=<put_your_rpc_server_url_here>
export NEAR_TESTNET_RPC=https://rpc.testnet.near.org
```
---

Expand Down
3 changes: 2 additions & 1 deletion bin/near-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ yargs // eslint-disable-line
.strict()
.scriptName('near')
.middleware(require('../utils/check-version'))
.middleware(require('../middleware/print-options'))
.middleware(require('../middleware/key-store'))
.middleware(require('../middleware/retro-ledger'))
.middleware(require('../middleware/print-options'))
.command(require('../commands/credentials/add'))
.command(require('../commands/keys/add'))
.command(require('../commands/contract/call'))
Expand Down
16 changes: 16 additions & 0 deletions middleware/retro-ledger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// In v3.5.0 the argument `useLedgerKey` was a string, in v4.0.0 this was change to a boolean
// Sadly, yargs assumes that --useLedgerKey='anything' is FALSE
// Here we detect if an argument is `useLedgerKey=` and guide the user to the correct format

module.exports = async function ledgerOptions() {
let path = '';

process.argv.forEach(arg => {
path = arg.includes('--useLedgerKey=') ? arg.split('=')[1] : path;
});

if (path != '') {
console.log(`\nPlease use --useLedgerKey --ledgerPath="${path}" instead of --useLedgerKey="${path}"\n`);
process.exit(0);
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "near-cli",
"version": "4.0.11",
"version": "4.0.13",
"description": "Simple CLI for interacting with NEAR Protocol",
"engines": {
"node": ">= 16"
Expand Down
2 changes: 2 additions & 0 deletions utils/connect.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { connect: nearConnect } = require('near-api-js');
const { getConfig } = require('../config');
const { getPublicKeyForPath, signForPath } = require('./ledger');
const chalk = require('chalk');

module.exports = async function connect({ keyStore, ...options }) {
// If using Ledger, override the signer so that it uses the Ledger device
if (options.signWithLedger) {
console.log(chalk`\nUsing Ledger with path {blue ${options.ledgerPath}}, change path with {blue --ledgerPath}\n`);
options.signer = {
getPublicKey: () => getPublicKeyForPath(options.ledgerPath),
signMessage: (m) => signForPath(m, options.ledgerPath)
Expand Down
4 changes: 3 additions & 1 deletion utils/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ async function getPublicKeyForPath(hdKeyPath) {
// cache keys to avoid confirming on Ledger multiple times
if (cachedPublicKeys[hdKeyPath]) return cachedPublicKeys[hdKeyPath];

console.log('Trying to connect with Ledger...');

transport = await TransportNodeHid.create();
client = await createClient(transport);

console.log('Getting Public Key from Ledger...');
console.log('Getting public key from Ledger...');

try {
const rawPublicKey = await client.getPublicKey(hdKeyPath);
Expand Down
Loading