1

I understand that there is a cost to storing data in table, my questions is how to estimate the cost.

{"key": "3773036822876127234",
"first_name": "bob",
"last_name": "smith",
"street": "123 My St",
"city": "Big City",
"state": "CA"}

The structure above is 131 bytes, names and address may vary in length and I could limit the length to max if needed. So is this examples cost 131 bytes which today is 0.0125 EOS, I calculated this by entering 0.131 KB into the ram calculator

Is it correct that the cost of retrieving the record is nothing? Does it cost anything to call a contract that searches the table and returns a value?

1

Not only bytes you store, but the size of index will be charged. Every row in multi_index will consume 112 bytes by default (for primary index) + actual data size (113 bytes in your case). You need to buy 225 bytes before storing your data. Moreover, if you add secondary indices by adding eosio::indexed_by to your multi_index typedef, it will charge more ram per each row.

  • In the example above im using key as the primary index and the first and last name are also indexed, could you show me how to calculate this? – Bill Jul 14 '19 at 3:34
  • What type of index do you use for first name and last name? Only five types (uint64_t, uint128_t, checksum256, double, long double) are allowed in secondary index and RAM usage will vary depending on what type of index you add. – conr2d Jul 14 '19 at 8:46
  • I dont know enough about converting text to numbers to answer this, I guess a max name length could be 30 characters, what happens when this becomes numbers? – Bill Jul 15 '19 at 6:47
  • You can use checksum256 (for storing 32-byte binary) type then. Each checksum256 index consume 160 bytes, so you'll need about 545 bytes per row. – conr2d Jul 15 '19 at 13:15
  • 1
    I'm not sure what you mean how many bytes the other types can store, but the five types for secondary index are uint64_t(8), uint128_t(16), checksum256(32), double(8) and long double(16). You can find related information from the next links: github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/… github.com/EOSIO/eos/blob/master/libraries/chain/include/eosio/… github.com/EOSIO/eos/blob/master/libraries/chain/include/eosio/… – conr2d Jul 16 '19 at 6:55

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.