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!