near-cli icon indicating copy to clipboard operation
near-cli copied to clipboard

CLI does not allow any JSON except map

Open austinabell opened this issue 2 years ago • 1 comments

Describe the bug

If anything except for a JSON map is put as the parameters for any call or view cli command, this error is returned:

PositionalArgsError: Contract method calls expect named arguments wrapped in object, e.g. 

{ argName1: argValue1, argName2: argValue2 } 

The issue is that the JSON does not have to be a map to be deserialized as parameters of a function. For example, in the near-sdk-rs, serde is used for the input parameters which allows deserializing as a map or an ordered sequence (JSON array).

So, if a method within near_bindgen is:

 pub fn method(param_a: u8, param_b: String) 

 {..} 

The parameters that would be valid are:


 {"param_a":8,"param_b":"some_val"} 

OR

[8,"some_val"]

but the latter is not allowed through CLI. This is very helpful when debugging quickly but also to minimize the size of the JSON being serialized and sent as input.

To Reproduce Steps to reproduce the behavior:

Call any method with anything except map JSON, for example: near call <account_id> method '[8,"some_val"]'

Expected behavior

Should let the request be sent off, because the tx would succeed if done correctly

austinabell avatar Jan 27 '22 16:01 austinabell

~~I believe we should avoid enabling error-prone ways of interaction. We use JSON format to ease reviewing the arguments and we drop the field names, we should better use borsh.~~

CLI should allow sending anything, even binary data. near.cli.rs does that just fine.

frol avatar Feb 15 '22 08:02 frol