Skip to content

contract invoke should auto-convert numbers to strings when parameter type is String #2334

@leighmcculloch

Description

@leighmcculloch

What problem does your feature solve?

When invoking a contract function that expects a String parameter and passing a number on the command line, the CLI errors instead of converting the number to a string.

Example contract:

#[contract]
pub struct Contract;

#[contractimpl]
impl Contract {
    fn test_string(v: String) -> String {
        v
    }
}

Invoking with a number fails:

$ stellar contract invoke --id c -- test_string --v 5
❌ error: Failed to parse argument 'v': invalid type: integer `5`, expected string or map

Context: Expected type string, but received: '5'

Suggestion: For strings, ensure the value is properly quoted (e.g., "hello world")

Passing a non-numeric string works:

$ stellar contract invoke --id c -- test_string --v lk
"lk"

What would you like to see?

Since the contract function signature specifies the parameter type is String, the CLI should automatically convert the integer 5 to the string "5" rather than erroring.

What alternatives are there?

The workaround is to double-quote the value: --v '"5"'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo (Ready for Dev)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions