From 1ca504f7af42744bccc4fcac306d7f588084fd1b Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 4 Jun 2019 20:31:05 -0700 Subject: [PATCH] Add command to send tokens --- bin/near | 8 ++++++++ index.js | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/bin/near b/bin/near index 5fcf8e0c..90a1bf76 100755 --- a/bin/near +++ b/bin/near @@ -46,6 +46,13 @@ const callViewFunction = { handler: (argv) => exitOnError(main.callViewFunction(argv)) }; +const sendTokens = { + command: 'send ', + desc: 'send tokens to given receiver', + builder: (yargs) => yargs, + handler: (argv) => exitOnError(main.sendTokens(argv)) +}; + const { spawn } = require('child_process'); const build = { command: 'build', @@ -129,6 +136,7 @@ yargs // eslint-disable-line .command(deploy) .command(scheduleFunctionCall) .command(callViewFunction) + .command(sendTokens) .command(clean) .command(newProject) .config(config) diff --git a/index.js b/index.js index 7674c9a2..2787d390 100755 --- a/index.js +++ b/index.js @@ -93,6 +93,13 @@ exports.scheduleFunctionCall = async function(options) { options.contractName, options.methodName, JSON.parse(options.args || '{}')))); }; +exports.sendTokens = async function(options) { + console.log(`Sending ${options.amount} NEAR to ${options.receiver}`); + const near = await connect(options); + await near.waitForTransactionResult( + await near.sendTokens(options.amount, options.accountId, options.receiver)); +}; + exports.callViewFunction = async function(options) { console.log(`View call: ${options.contractName}.${options.methodName}(${options.args || ''})`); const near = await connect(options);