-
Notifications
You must be signed in to change notification settings - Fork 92
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 #227 from nearprotocol/fix-initial-balance
Convert --initialBalance from NEAR tokens to integer units
- Loading branch information
Showing
4 changed files
with
52 additions
and
44 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,50 @@ | ||
|
||
const exitOnError = require('../utils/exit-on-error'); | ||
const connect = require('../utils/connect'); | ||
const { KeyPair, utils } = require('nearlib'); | ||
|
||
module.exports = { | ||
command: 'create_account <accountId>', | ||
desc: 'create a new developer account', | ||
builder: (yargs) => yargs | ||
.option('accountId', { | ||
desc: 'Unique identifier for the newly created account', | ||
type: 'string', | ||
required: true | ||
}) | ||
.option('masterAccount', { | ||
desc: 'Account used to create requested account.', | ||
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', | ||
default: '0.1' | ||
}), | ||
handler: exitOnError(createAccount) | ||
}; | ||
|
||
async function createAccount(options) { | ||
options.initialBalance = utils.format.parseNearAmount(options.initialBalance); | ||
// NOTE: initialBalance is passed as part of config here | ||
let near = await connect(options); | ||
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.`); | ||
} |
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