Getting the Error 3160003: Invalid table iterator error while trying to execute:

 cleos push action voting.debug debug '[ 0 ]' -p user@active

I have a simple voting contract (full code) where I'm trying to print candidate by id.

Here is a chunk of code which probably doesn't work:

  /// @abi action
  void debug( uint64_t id ) {
    print("Hello, ", name{getcandidate(id)});

  /// @abi action
  account_name getcandidate( uint64_t id ) const {
    Candidates candidates( _self, _self );
    auto element = candidates.find( id );
    return element->name;

The struct which is stored in multi-index table candidates:

struct candidate {
  uint64_t id;
  account_name name;

  auto primary_key() const { return id; }
typedef eosio::multi_index<N(candidates), candidate> Candidates;

Appreciate any help and advice. I'm using eos 1.1.0.

1 Answer 1


If your table doesn't have any elements, then it will throw this error.

Whenever you use the find command, always check afterwards that an element was found:

auto element = candidates.find( id );
if(element != candidates.end())
  return element_name;
  • I have this line (/// @abi table your_table_name i64) here: gist.github.com/RomanFro/…. Aug 19, 2018 at 8:38
  • 1
    Thank you for answer, it seems like the problem resolved. I forgot to add records to the table and the error message was invoked due to trying to access the id which is absent in the table. Aug 19, 2018 at 8:40
  • Ok, I will update my answer to show that Aug 19, 2018 at 8:45
  • how do I check when I'm using .begin() instead? I have a declaration like this auto matches = t.get_index<name(”myidx”)>(); after which I do this: for (auto match = matches.begin(); match != matches.end(); match++) { and when I run it, I get the error: ”3160003 invalid_table_iterator: Invalid table iterator”… if I compare matches.begin() == matches.end() I get a false
    – ekkis
    Dec 19, 2019 at 22:44
  • 1
    @ekkis I recommend posting your own question and showing the code Jan 13, 2020 at 16:03

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.