#Unable to Pass Vec<Val> Argument When Invoking Soroban Contract Using Stellar CLI

1 messages · Page 1 of 1 (latest)

arctic sluice
#

I am trying to call a Soroban contract function that takes a Vec<Val> as an argument using the Stellar CLI. However, I keep getting errors related to argument formatting.
Function in the Contract:

pub fn call(env: Env, args: Vec<Val>) { let method_name = Symbol::new(&env, "message"); let contract = Address::from_string(&String::from_str( &env, "CDJ2UM2CPYVIVKANDIV6WWZZQBRVY52Z52PJQK6JFZO4RAW3RLLP4T3Z", )); env.invoke_contract(&contract, &method_name, args); }

Target Function Being Called:

pub fn message(env: Env, txt: String) { env.events().publish((MESSAGE, symbol_short!("message")), txt.clone()); }

CLI Command Attempted:

stellar contract invoke \ --id CBV5HFFAKYDDRTEKH4NMASXN7QECDLUMGUP766JIY3ZSMF777F2JOYIG \ --source SECRET-KEY \ --network testnet \ -- call \ --args '[["string", "David"]]'

Errors Encountered:

❌ error: parsing argument args: invalid type: unit variant, expected newtype variant
❌ error: parsing argument args: unknown variant "David", expected one of...
❌ error: parsing argument args: invalid value: map, expected map with a single key

I've tried multiple argument formats, including JSON, nested lists, and different string representations, but nothing seems to work.
Question:

What is the correct way to pass a Vec<Val> argument in Stellar CLI when calling a contract function?
How should a string argument be correctly formatted in this case?

Any help would be greatly appreciated!

limpid pecan
#

Did you try --args '["David"]'? I could be wrong, but I don't think you have to specify what the type is for the Val to be parsed/interpreted correctly

#

I recently had a function with a vector of addresses, and if I remember right, it went like --addresses '["CA...", "CB...", "CC..."]'

#

Though it's possible the CLI will get confused and think you're passing a Symbol instead of a String? In that case, maybe try with a longer name that wouldn't fit into a symbol's length.