diff --git a/bin/near b/bin/near index 5b3bf2de..660f7d64 100755 --- a/bin/near +++ b/bin/near @@ -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', { @@ -162,6 +184,7 @@ yargs // eslint-disable-line .command(sendTokens) .command(clean) .command(newProject) + .command(stake) .config(config) .alias({ 'accountId': ['account_id'], diff --git a/index.js b/index.js index 0e229560..ec5319c0 100755 --- a/index.js +++ b/index.js @@ -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)); +}