text is too large. string is too small. What can I do?

LukeDLukeD Member Posts: 23
I want to store URLs in a contract, which means I need a string of at most 16kB in size. However, I can probably get away with having a 2 or 4 kB string.

Unfortunately, Solidity only seems to support 256B strings and 64kB text objects. 32 ascii characters is way too small, and 8,192 ascii characters is way too many. What can I do to get strings of different sizes?


  • LukeDLukeD Member Posts: 23
    Sorry, my numbers are wrong. strings are 32B, not 256B. And I need at most a 2kB string to store a URL, but I can probably get away with as little as 0.25kB.
  • chrisethchriseth Member Posts: 170 ✭✭✭
    There are (or rather will be, as this is not all implemented yet) fixed size and variable size strings. Fixed size strings of less than 32 bytes will fit into one storage slot, so they will all cost the same with regards to storage.
    If you have strings with different sizes, you probably want to use the 'string' or 'text' type, which will only take as much storage as they need plus an additional slot that contains the length of the string.
  • cslarsoncslarson Member Posts: 11
    chriseth, thanks for your work developing solidity. the variable length 'string' or 'text' types do not seem to be available to use yet, at least in alethzero. is there a timeline for their implementation?
  • chrisethchriseth Member Posts: 170 ✭✭✭
    The backlog says it could be there in the middle of march, but this is not guaranteed in any way.
Sign In or Register to comment.