diff --git a/README.md b/README.md
index d8140e58..2c88a47e 100644
--- a/README.md
+++ b/README.md
@@ -380,7 +380,7 @@ near generate-key example.testnet --seedPhrase="cow moon right send now cool den
#### 1) add a `full access` key
-- arguments: `accountId` `publicKey`
+- arguments: `accountId` `--access-key`
**Example:**
@@ -402,7 +402,7 @@ near add-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S
#### 2) add a `function access` key
-- arguments: `accountId` `publicKey` `--contract-id`
+- arguments: `accountId` `--access-key` `--contract-id`
- options: `--method-names` `--allowance`
> `accountId` is the account you are adding the key to
@@ -418,7 +418,7 @@ near add-key example-acct.testnet Cxg2wgFYrdLTEkMu6j5D6aEZqTb3kXbmJygS48ZKbo1S
**Example:**
```bash
-near add-key example-acct.testnet GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi --contract-id example-contract.testnet --method-names example_method --allowance 30000000000
+near add-key example-acct.testnet --access-key GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi --contract-id example-contract.testnet --method-names example_method --allowance 30000000000
```
@@ -433,6 +433,30 @@ near add-key example-acct.testnet GkMNfc92fwM1AmwH1MTjF4b7UZuceamsq96XPkHsQ9vi -
+
+#### 3) add a `full access` key based on a seed phrase
+
+- arguments: `accountId` `--seedPhrase="[your seed phrase]"`
+
+**Example:**
+
+```bash
+near add-key example-acct.testnet --seedPhrase="cow moon right send now cool dense quark pretty see light after"
+```
+
+
+Example Response
+
+
+ Adding seed phrase as full access key = "cow moon right send now cool dense quark pretty see light after" to example-acct.testnet.
+ Transaction Id EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJg
+ To see the transaction in the transaction explorer, please open this url in your browser
+ https://explorer.testnet.near.org/transactions/EwU1ooEvkR42HvGoJHu5ou3xLYT3JcgQwFV3fAwevGJg
+
+
+
+
+
---
### `near delete-key`
diff --git a/commands/add-key.js b/commands/add-key.js
index 70221b34..1bb60600 100644
--- a/commands/add-key.js
+++ b/commands/add-key.js
@@ -5,13 +5,13 @@ const { utils } = require('near-api-js');
const checkCredentials = require('../utils/check-credentials');
module.exports = {
- command: 'add-key ',
+ command: 'add-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,
+ required: false,
})
.option('contract-id', {
desc: 'Limit access key to given contract (if not provided - will create full access key)',
@@ -33,9 +33,29 @@ module.exports = {
async function addAccessKey(options) {
await checkCredentials(options.accountId, options.networkId, options.keyStore);
- 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);
+
+ if(options.seedPhrase){
+ if(options.contractId){
+ console.log("Seed phrase key must be a full access key");
+ return;
+ }
+ console.log(`Adding seed phrase as full access key to ${options.accountId}`);
+
+ const result = await account.addKey(options.seedPhrasePublicKey);
+ inspectResponse.prettyPrintResponse(result, options);
+
+ return;
+ }
+
+ if(!options.accessKey){
+ console.log("access-key to be added must be specified");
+ return;
+ }
+
+ console.log(`Adding ${options.contractId ? 'function call access' : 'full access'} key = ${options.accessKey} to ${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);
diff --git a/middleware/seed-phrase.js b/middleware/seed-phrase.js
index 4c326492..c2afb871 100644
--- a/middleware/seed-phrase.js
+++ b/middleware/seed-phrase.js
@@ -18,8 +18,8 @@ module.exports = async function useSeedPhrase({ seedPhrase, seedPath, keyStore,
const seedPhraseKeystore = new InMemoryKeyStore();
const seedPhraseAccountId = masterAccount ? masterAccount : accountId || implicitAccountId(publicKey);
- await keyStore.setKey(networkId, seedPhraseAccountId, KeyPair.fromString(secretKey));
+ await seedPhraseKeystore.setKey(networkId, seedPhraseAccountId, KeyPair.fromString(secretKey));
if(keyStore instanceof MergeKeyStore) keyStore.keyStores.push(seedPhraseKeystore);
- return { keyStore, accountId };
+ return { keyStore, accountId, seedPhrasePublicKey: publicKey };
};