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

Implement add-key option #529

Merged
merged 4 commits into from
Sep 15, 2020
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
1 change: 1 addition & 0 deletions bin/near-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ yargs // eslint-disable-line
.command(login)
.command(require('../commands/repl'))
.command(require('../commands/generate-key'))
.command(require('../commands/add-key'))
.command(require('../commands/delete-key'))
.command(require('../commands/validators'))
.command(require('../commands/proposals'))
Expand Down
40 changes: 40 additions & 0 deletions commands/add-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const inspectResponse = require('../utils/inspect-response');
const { utils } = require('near-api-js');

module.exports = {
command: 'add-key <account-id> <access-key>',
desc: 'Add an access key to given account',
builder: (yargs) => yargs
.option('access-key', {
desc: 'Public key to add (base58 encoded)',
type: 'string',
required: true,
})
.option('contract-id', {
desc: 'Limit access key to given contract (if not provided - will create full access key)',
type: 'string',
required: false,
})
.option('method-names', {
desc: 'Method names to limit access key to (command separated)',
type: 'string',
required: false,
})
.option('allowance', {
desc: 'Allowance in $NEAR for the key (default 0)',
type: 'string',
required: false,
}),
handler: exitOnError(addAccessKey)
};

async function addAccessKey(options) {
console.log(`Adding ${options.contractId ? 'function call access' : 'full access'} key = ${options.accessKey} to ${options.accountId}.`);
const near = await connect(options);
const account = await near.account(options.accountId);
const allowance = utils.format.parseNearAmount(options.allowance);
const result = await account.addKey(options.accessKey, options.contractId, options.methodNames, allowance);
inspectResponse.prettyPrintResponse(result, options);
}
4 changes: 2 additions & 2 deletions commands/delete-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const connect = require('../utils/connect');
const inspectResponse = require('../utils/inspect-response');

module.exports = {
command: 'delete-key [accessKey]',
command: 'delete-key <account-id> <access-key>',
desc: 'delete access key',
builder: (yargs) => yargs
.option('accessKey', {
.option('access-key', {
desc: 'Public key to delete (base58 encoded)',
type: 'string',
required: true,
Expand Down