Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

CLI does not allow any JSON except map #920

Open
austinabell opened this issue Jan 27, 2022 · 1 comment
Open

CLI does not allow any JSON except map #920

austinabell opened this issue Jan 27, 2022 · 1 comment

Comments

@austinabell
Copy link

austinabell commented Jan 27, 2022

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 austinabell transferred this issue from near/near-api-js Jan 27, 2022
@frol
Copy link
Collaborator

frol commented Feb 15, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants