0

How can I query a smart contract table to return a row instead of using the primary key id?

I have the following: https://jungle.bloks.io/account/mybest111111?loadContract=true&tab=Tables&account=mybest111111&scope=mybest111111&limit=100

I want to return the row based on the asset_id. I'm doing this in C++ contract code.

1 Answer 1

0

first of all please consult the multi-index table documentation:

https://developers.eos.io/manuals/eosio.cdt/latest/how-to-guides/multi-index/index

in your question you say you want to query the table without using the primary key and later you say you want to query it based on asset_id; but it seems asset_id is your primary key. I assume this is a typo and you want to query based on any other field BUT asset_id.

in this case you have to create a secondary index and query the table using it.

see this doc page on how to define a secondary index:

https://developers.eos.io/manuals/eosio.cdt/latest/how-to-guides/multi-index/how-to-define-a-secondary-index

and this page on how to use a secondary index: https://developers.eos.io/manuals/eosio.cdt/latest/how-to-guides/multi-index/how-to-iterate-and-retrieve-a-multi_index-table-based-on-secondary-index

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.