How do I build an AccountAddress from a String in Rust?

As per the title. I have a String being passed in to represent the AccountAddress but for logging purposes I need the AccountAddress structure.

I could not see an example of this in the sample repo, perhaps I just missed it?

Do you mean

let address_string = "4RBHsovUPUyA8yNZkPtq9LTpLgjbNoHy4uDxX4QXAPEcWkQcPK";

let address = address_string.parse::<AccountAddress>()

In this case address will have type Result<AccountAddress, SomeError> You should either propagate this error using ? or unwrap if you are certain it cannot happen.

This seems to generate the error:

the trait bound concordium_std::AccountAddress: FromStr is not satisfied

Is there something else I need to do?

Oh, you are using this inside a smart contract.

There the FromStr is not available since it brings in quite a few dependencies (to do base58 checks).

Inside a smart contract you should generally not need to have a String passed in as an account address though. So can you elaborate what your use-case is where this is needed?

We are hashing the AccountAddresses on the front end and smart contract so for consistency we were handling everything as strings however the mint event requires an AccountAddress.

Is there a reason why you don’t want to be hashing the parsed byte arrays instead?