From 4a7cd4931c0880688d7e2b112ed16afb9d22b92f Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 4 Jun 2019 20:14:53 -0700 Subject: [PATCH 1/2] Allow passing token amount with scheduled function call --- bin/near | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/near b/bin/near index 62e5ad67..5fcf8e0c 100755 --- a/bin/near +++ b/bin/near @@ -30,7 +30,12 @@ const deploy = { const scheduleFunctionCall = { command: 'call [args]', desc: 'schedule smart contract call which can modify state', - builder: (yargs) => yargs, + builder: (yargs) => yargs + .option('amount', { + desc: 'Number of tokens to attach', + type: 'string', + default: '1000000000' + }), handler: (argv) => exitOnError(main.scheduleFunctionCall(argv)) }; From 1ca504f7af42744bccc4fcac306d7f588084fd1b Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 4 Jun 2019 20:31:05 -0700 Subject: [PATCH 2/2] 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);