Skip to content

Commit

Permalink
Merge pull request #49 from nearprotocol/tokens-amount
Browse files Browse the repository at this point in the history
Allow passing token amount with scheduled function call
  • Loading branch information
vgrichina authored Jun 5, 2019
2 parents 6e8361c + 1ca504f commit 34e55cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bin/near
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ const deploy = {
const scheduleFunctionCall = {
command: 'call <contractName> <methodName> [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))
};

Expand All @@ -41,6 +46,13 @@ const callViewFunction = {
handler: (argv) => exitOnError(main.callViewFunction(argv))
};

const sendTokens = {
command: 'send <receiver> <amount>',
desc: 'send tokens to given receiver',
builder: (yargs) => yargs,
handler: (argv) => exitOnError(main.sendTokens(argv))
};

const { spawn } = require('child_process');
const build = {
command: 'build',
Expand Down Expand Up @@ -124,6 +136,7 @@ yargs // eslint-disable-line
.command(deploy)
.command(scheduleFunctionCall)
.command(callViewFunction)
.command(sendTokens)
.command(clean)
.command(newProject)
.config(config)
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 34e55cf

Please sign in to comment.