Problem Say I have a table with the following structure.

int value | asset tokenType
4    | 0 bitcoin 
7    | 0 altcoin. 

Now I also have this function where I pass in an asset and i want to retrieve the value. Pretend I pass in bitcoin as coinType.

I know I can say

auto iterator = table.find(coinType.symbol.raw());

and iterator will be that row or be at the end if nothing is found.

HOWEVER, what I am trying to accomplish is selecting this 7. Something like "SELECT But how can I SELECT value ( which would be 7), like I would in sql. ( I know this isn't sql btw )

But this is my table structure

TABLE items{
   int id;
   asset value ;
   asset tokenType;
   std:: string note;
  //Primary key is symbol of tokenType
  uint64_t primary_key() const {return tokenType.symbol.raw();}


2 Answers 2


Ok, now that I read your question again I see that I maybe misunderstood the question.

auto iterator = table.find(coinType.symbol.raw());

returns a pointer to the dataset with the specific value.

If you want to access members of the row behind the pointer you have to use the

arrow-operator "->"


int test_access_member = iterator->id;

will let you access the value.

You should take a look at C/C++ pointers and references.


At first, there's nothing like "SELECT"-Statements

If you want to find by rows by values of a certain column you need to add more indexes. In your case:

long secondary_key() const {return id;}
typedef eosio::multi_index<"assets"_n, asset, eosio::indexed_by<"id"_n, eosio::const_mem_fun<asset, long, &asset::secondary_key>>> assetstable;

Now you can use find on the id-column if you do

auto id_index = table.get_index<N(byid)>();
auto row = id_index.find(id);

But note that you have to use at minimum a 64-bit type as index-type.

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.