diff --git a/README.md b/README.md index 43d621e2..2fb0b730 100644 --- a/README.md +++ b/README.md @@ -1312,6 +1312,7 @@ With NEAR REPL you have complete access to [`near-api-js`](https://github.com/ne | `--contractName` | Account name of contract [string] | | `--masterAccount` | Master account used when creating new accounts [string] | | `--helperAccount` | Expected top-level account for a network [string] | +| `--base64file` | Load a base64-encoded BLOB file into the args sent to a function call [string] | | `-v, --verbose` | Prints out verbose output [boolean] [default: false] | |`-f, --force` | Forcefully execute the desired action even if it is unsafe to do so [boolean] [default: false]| diff --git a/commands/call.js b/commands/call.js index 35cb6234..77cc7435 100644 --- a/commands/call.js +++ b/commands/call.js @@ -1,3 +1,4 @@ +const { readFileSync } = require('fs'); const { DEFAULT_FUNCTION_CALL_GAS, providers, utils } = require('near-api-js'); const exitOnError = require('../utils/exit-on-error'); const connect = require('../utils/connect'); @@ -39,6 +40,11 @@ module.exports = { required: true, desc: 'Unique identifier for the account that will be used to sign this call', type: 'string' + }) + .option('base64file', { + desc: 'Load a base64-encoded BLOB file into the args sent to a function call.', + type: 'string', + default: false }), handler: exitOnError(scheduleFunctionCall) }; @@ -51,7 +57,19 @@ async function scheduleFunctionCall(options) { const near = await connect(options); const account = await near.account(options.accountId); - const parsedArgs = options.base64 ? Buffer.from(options.args, 'base64') : JSON.parse(options.args || '{}'); + let parsedArgs; + // load args rare order first + if (options.base64file) { + try { + let fileargs = await readFileSync(options.base64file); + parsedArgs = Buffer.from(fileargs, 'base64'); + console.log(`Loaded base64 args file, size ${parsedArgs.length}`); + } catch (e) { + throw new Error('Could not load base64 file!'); + } + } + if (!parsedArgs && options.base64) parsedArgs = Buffer.from(readFileSync(options.args), 'base64'); + if (!parsedArgs) parsedArgs = JSON.parse(options.args || '{}'); console.log('Doing account.functionCall()'); try { const functionCallResponse = await account.functionCall({