4

Around one year ago I have implemented simple DEX in ink!, but today I want to migrate the code to newest ink! and I have an error, in the code I have:

use ink_storage::collections::HashMap;

And this line made me strong headache. Is is possible to use HashMap in ink! If so, how?

I know that the question could be "simple" for someone who writes ink! on daily basis, but I would say thanks for three cents of empathy and awareness that not everyone writes code in ink! every day. I was looking for the answer in documentation, and the link that in my humble opinion makes sense, does not work: https://paritytech.github.io/substrate/master/scale_info/prelude/collections/struct.HashMap.html

1

1 Answer 1

6

We had to remove HashMap in with 3.0 unfortunately (context here).

It was instead replaced with the simpler ink::storage::Mapping. You should be able to have the same functionality with this data structure. If not, please create a GitHub issue or another StackExchange question.

The main reason for removing HashMap was that it required complex code and we found that this overhead bloated the compiled contract‘s size to a level where it was not economical anymore to deploy or use these contracts.

You might encounter other issues with upgrading from 3.x to 4.0. We've written this migration guide.

From your question I gather that you might be using some beta or release candidate of 3.0, so it might be that there is something missing in the migration guide then. If you encounter more issues, please just create a another question here or a GitHub issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.