Let's say I'm making a game character and each eos account is a unique character. Is there a way to mark an account with different properties like strength, speed, durability, etc....

  • yeah you can use the account name as the primary key in the contract RAM table and use the properties as fields in the struct. monstereos had something similar I think
    – confused00
    Oct 10 '18 at 23:06
  • link to examples? Oct 11 '18 at 3:18

Yes, you can use use multi-index tables to store the relevant data in the persistent storage while indexing it by account name. To access the persistent storage, you'd need to have bought RAM to pay for the storage while it's in use.

Example adapted from the docs:

struct [[eosio::table]] mystruct 
    name            key; 
    uint64_t        strength;
    uint64_t        durability; 
    uint64_t        speed; 

    uint64_t primary_key() const { return key.value; } // getter for primary key

typedef eosio::multi_index<"mystruct"_n, mystruct> datastore;

Other projects such as EOSKnights show a working app using similar concepts.

  • where is this persistent storage? I thought EOS doesn't store data like this? Or wouldn't it be too expensive? Oct 11 '18 at 14:25
  • yes, you need to buy RAM to have access to the persistent storage, and at the moment it's about 0.1 EOS per KiB (updated my answer to mention RAM as well)
    – confused00
    Oct 11 '18 at 14:30
  • You don't necessarily have to buy RAM, you can put it on the users' account. So each user needs a small amount of RAM and they all share the cost.
    – Ami Heines
    Nov 10 '18 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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