-
Notifications
You must be signed in to change notification settings - Fork 93
Convert --initialBalance from NEAR tokens to integer units #227
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why we change it to 0.1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that if you have created your master account in wallet, you can create multiple accounts in shell without completely draining master account balance (it's 10 NEAR by default). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is not a good way to do so. give more instructions to user what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you suggest not having default amount at all? or different default amount? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe not having default amount but required amount from user is better. since 0.1 or even less is not good number to guess how many account user want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree there is some trade off between discoverability and convenience here. However I highly prefer tools where you can succeed most of the time with reasonable details. We need to make sure to have |
||
}), | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanna know the function createAccount here is never received the arg initialBalance, how could it really pass the commend arg initialBalance to create new account with specific token? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above: // NOTE: initialBalance is passed as part of config here
let near = await connect(options); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it |
||
if (keyPair) { | ||
await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair); | ||
} | ||
console.log(`Account ${options.accountId} for network "${options.networkId}" was created.`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to pulling out commands into separate files!