diff --git a/bin/near b/bin/near index f577c086..a6ed452c 100755 --- a/bin/near +++ b/bin/near @@ -34,6 +34,13 @@ const scheduleFunctionCall = { handler: (argv) => exitOnError(main.scheduleFunctionCall(argv)) }; +const callViewFunction = { + command: 'call_view_function [args]', + desc: 'make smart contract call which can view state', + builder: (yargs) => yargs, + handler: (argv) => exitOnError(main.callViewFunction(argv)) +}; + const { spawn } = require('child_process'); const build = { command: 'build', @@ -111,6 +118,7 @@ yargs // eslint-disable-line .command(build) .command(deploy) .command(scheduleFunctionCall) + .command(callViewFunction) .command(clean) .command(newProject) .config(config) diff --git a/index.js b/index.js index 578969ee..0bad3be5 100755 --- a/index.js +++ b/index.js @@ -91,4 +91,11 @@ exports.scheduleFunctionCall = async function(options) { console.log('Result:', await near.waitForTransactionResult( await near.scheduleFunctionCall(options.amount, options.accountId, options.contractName, options.methodName, JSON.parse(options.args || '{}')))); +}; + +exports.callViewFunction = async function(options) { + console.log(`View call: ${options.contractName}.${options.methodName}(${options.args || ''})`); + const near = await connect(options); + console.log('Result:', await near.waitForTransactionResult( + await near.callViewFunction(options.contractName, options.methodName, JSON.parse(options.args || '{}')))); }; \ No newline at end of file