2

Whenever I try to make a list of strings (2D array), I get this error Multidimensional String arrays are not supported. This is the code I tried: names: String[30][100]. Does anyone know how to help? (version 0.3.1)

2
  • Use solidity or manage the array by yourself names: String[3000].
    – Ismael
    Feb 9, 2022 at 6:23
  • 2
    I figured out how to use a hashmap. Feb 10, 2022 at 12:09

2 Answers 2

1

I think 2D String arrays are possible now in Vyper 0.3.7. Example:

   DynArray[String[3], 10]
3
  • This seems only a little better than my current solution, but I already deployed my site and contract. You can achieve the same thing with the above solution. Jan 6, 2023 at 12:08
  • @thegamebegins25 Glad you found a solution that works in your contract! I'm just learning Vyper. I didn't deploy a real contract yet.
    – devdanke
    Jan 7, 2023 at 17:55
  • 1
    Differences that may be important to others: HashMap is a storage variable only. It can't be a local variable. On the other hand, DynArrays can be local or storage variables in a function. DynArrays can be passed to and returned by functions. I am not sure of the storage cost differences between HashMap and DynArray.
    – devdanke
    Jan 7, 2023 at 17:56
2

I figured it out, I can use a hashmap.

names: HashMap[uint256, String[30]]

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.