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

Commit

Permalink
Merge pull request #78 from nearprotocol/j-createAccountPublicKey
Browse files Browse the repository at this point in the history
Create account : add option to pass a public key
  • Loading branch information
janedegtiareva authored Jul 25, 2019
2 parents ffb4a39 + c942019 commit 3814995
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions bin/near
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ const createAccount = {
type: 'string',
required: true
})
.option('publicKey', {
desc: 'Public key to initialize the account with',
type: 'string',
required: false
})
.option('initialBalance', {
desc: 'Number of tokens to transfer to newly created account',
type: 'string',
Expand Down
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ async function connect(options) {

exports.createAccount = async function(options) {
let near = await connect(options);
const keyPair = await KeyPair.fromRandom('ed25519');
await near.createAccount(options.accountId, keyPair.getPublicKey());
near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair);
let keyPair;
let publicKey;
if (options.publicKey) {
publicKey = options.publicKey;
} else {
keyPair = await KeyPair.fromRandom('ed25519');
publicKey = keyPair.getPublicKey();
}
await near.createAccount(options.accountId, publicKey);
if (keyPair) {
await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair);
}
console.log(`Account ${options.accountId} for network "${options.networkId}" was created.`);
}

Expand Down

0 comments on commit 3814995

Please sign in to comment.