Skip to content

Commit

Permalink
Convert --initialBalance from NEAR tokens to integer units
Browse files Browse the repository at this point in the history
This also changes default value to 0.1 NEAR
  • Loading branch information
vgrichina committed Dec 23, 2019
1 parent 6b579bb commit 9139d0c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions commands/create-account.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const { KeyPair } = require('nearlib');
const { KeyPair, utils } = require('nearlib');

module.exports = {
command: 'create_account <accountId>',
Expand All @@ -25,12 +25,14 @@ module.exports = {
.option('initialBalance', {
desc: 'Number of tokens to transfer to newly created account',
type: 'string',
default: '10'
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;
Expand All @@ -40,7 +42,6 @@ async function createAccount(options) {
keyPair = await KeyPair.fromRandom('ed25519');
publicKey = keyPair.getPublicKey();
}
// TODO: Needs to pass initialBalance converted from NEAR tokens
await near.createAccount(options.accountId, publicKey);
if (keyPair) {
await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair);
Expand Down

0 comments on commit 9139d0c

Please sign in to comment.