cargo-contract icon indicating copy to clipboard operation
cargo-contract copied to clipboard

String arguments need weird double quote combination to work: '"<string>"'

Open Daanvdplas opened this issue 4 months ago • 2 comments

In order to instantiate a contract with argument String I need to wrap the string in the terminal with '", example: --args '"argument"'

Daanvdplas avatar Aug 14 '25 16:08 Daanvdplas

We have a similar issue opened by a user in pop-cli https://github.com/r0gue-io/pop-cli/issues/408

➜  inputs cargo contract instantiate --suri //Alice --args false "value" -x
ERROR: Expected a String value
On the command-line, String values need to be wrapped in escaped quotes: \"…\".

@cmichi was there a reason not to have it under \"

AlexD10S avatar Sep 04 '25 13:09 AlexD10S

So this behavior goes back to how bash treats double quotes. Before passing arguments to a command, bash will remove the double quotes. It's why things like rm "foo" also work.

In our case, cargo-contract never sees the "value" from cargo contract instantiate -args "value", but just value. The easy solution is to escape it, then cargo-contract (or rather the crate parsing the commandline args) knows it's a string.

I also think this should be done better, but it's likely not a straight forward issue. I believe the most intuitive solution would be to also support --args 'my argument', but --args "my argument" will likely never work (as the process just sees --args my argument).

cmichi avatar Sep 12 '25 20:09 cmichi