diff --git a/bin/near b/bin/near index ab32c3b5..09c40890 100755 --- a/bin/near +++ b/bin/near @@ -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', diff --git a/index.js b/index.js index bf1ec2c2..88305ea0 100755 --- a/index.js +++ b/index.js @@ -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.`); }