Skip to content

Commit

Permalink
Add staking command
Browse files Browse the repository at this point in the history
  • Loading branch information
ilblackdragon committed Jun 12, 2019
1 parent d04ceaf commit cd78486
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bin/near
Expand Up @@ -119,6 +119,28 @@ const newProject = {
handler: (argv) => exitOnError(main.newProject(argv))
};

const stake = {
command: 'stake [accountId] [publicKey] [amount]',
desc: 'create staking transaction',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to stake on',
type: 'string',
required: true,
})
.option('publicKey', {
descr: 'Public key to stake with (base58 encoded)',
type: 'string',
required: true,
})
.option('amount', {
descr: 'Amount to stake',
type: 'string',
required: true,
}),
handler: (argv) => exitOnError(main.stake(argv))
}

let config = require('../get-config')();
yargs // eslint-disable-line
.option('nodeUrl', {
Expand Down Expand Up @@ -162,6 +184,7 @@ yargs // eslint-disable-line
.command(sendTokens)
.command(clean)
.command(newProject)
.command(stake)
.config(config)
.alias({
'accountId': ['account_id'],
Expand Down
8 changes: 8 additions & 0 deletions index.js
Expand Up @@ -97,3 +97,11 @@ exports.callViewFunction = async function(options) {
const near = await connect(options);
console.log('Result:', await near.callViewFunction(options.contractName, options.methodName, JSON.parse(options.args || '{}')));
};

exports.stake = async function(options) {
console.log(`Staking ${options.amount} on ${options.accountId} with public key = ${options.publicKey}.`);
const near = await connect(options);
const account = await near.account(options.accountId);
const result = await account.stake(options.publicKey, BigInt(options.amount));
console.log('Result: ', JSON.stringify(result));
}

0 comments on commit cd78486

Please sign in to comment.