-
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.
- Loading branch information
1 parent
1712b50
commit 266e492
Showing
2 changed files
with
45 additions
and
0 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,44 @@ | ||
const BN = require('bn.js'); | ||
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 [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 on the key (default 0)', | ||
type: 'string', | ||
required: false, | ||
}), | ||
handler: exitOnError(addAccessKey) | ||
}; | ||
|
||
async function addAccessKey(options) { | ||
if (!options.accountId) { | ||
return; | ||
} | ||
console.log(`Adding ${options.contractId ? 'limited 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); | ||
} |