-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from near/add-key
Implement add-key option
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters