How to take a variable length string as a input for a function in contract?

I would like to know how to get a variable length string as an input for a function in a contract. I have a StorageString that can store the string. Below is my sample code.

#[storage(read, write)]
    fn set_name(n: String) {
        storage.name.write_slice(n);
    }

#[storage(read)]
    fn get_name() -> String {
        return storage.name.read_slice().unwrap();
    }
1 Like

For anyone interested, this solution actually works. You can input a plain UTF-8 string and read it back.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.