I'm developing a Smart Contract for EOSIO. I have a Multi-Index table with a uint64_t primary key. I'd like to add a secondary index to the table.

Ideally the data I'd be indexing on would be a std::string, but I'm under the impression that EOS does not allow that. I do see something in the documentation referred to as an idx256 described as a "256-bit fixed-size lexicographical key", though it is unclear how to construct one.

How do I create an idx256? What conversions must I do to a std::string to make it work (truncate or otherwise manipulate)? What are my limitations (for instance, is this a one-way conversion similar to hashing)? Any gotchas or other concerns I should be aware of?


1 Answer 1


As of eosio.cdt v1.5.0, you can not make a secondary index from a string.

The types of secondary indices allowed are:

    uint64_t    secondary_1;
    uint128_t   secondary_2;
    checksum256 secondary_3;
    double      secondary_4;
    long double secondary_5;

In principle, you could encode your string as a eosio::name and store it in a uint64_t, but this limits you to the 12 character-style names for eosio accounts.

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.