I am creating a local instance of multi index table (following the example given in this tutorial: https://developers.eos.io/eosio-cpp/docs/using-multi-index-tables) but when I try to compile I get the following error:

error: use of undeclared identifier '_ktcusers'

On line: auto user_iterator = _ktcusers.find(user.value);

Not sure what I am missing. My code below:

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>

using namespace eosio;

class [[eosio::contract]] ktc : public eosio::contract {


    ktc( eosio::name receiver, eosio::name code,  eosio::datastream<const char*> ds ): eosio::contract(receiver, code, ds), _ktcusers(receiver, code.value) {}

    [[eosio::action]] void upsert(name user);

    struct [[eosio::table]] ktcuser {
      name key;
      std::string first_name;
      std::string last_name;
      std::string street;
      std::string city;
      std::string state;
      uint64_t primary_key() const { return key.value; }

    typedef eosio::multi_index<"ktcuser"_n, ktcuser> ktcusers;

    //local instance of multi index table
    ktcusers _ktcusers;

#include "ktc.hpp"

void upsert(name user) {

    // Ensure this action is authorized by the player

    // Create a record in the table
    auto user_iterator = _ktcusers.find(user.value);
    if (user_iterator == _ktcusers.end()) {
        user_iterator = _ktcusers.emplace(user,  [&](auto& new_user) {
        new_user.key = user;


EOSIO_DISPATCH( ktc, (login))
  • Well after spending a lot of time on this, all I can say for certain is that the primary index of the multi index container must be a uint64_t per the docs, and that the contract's file name must match the class declaration name.
    – Nat
    Nov 29, 2018 at 8:12
  • 1
    in ktc.cpp void upsert(name user) -> void ktc::upsert(name user). EOSIO_DISPATCH( ktc, (login)) -> EOSIO_DISPATCH( ktc, (upsert)) Nov 29, 2018 at 12:43
  • 1
    Chaging void upsert(name user) to void ktc::upsert(name user) did the trick. It compiled now. Thank you!
    – Jyothi
    Nov 29, 2018 at 19:53

1 Answer 1


Per Cooper Goldcrest's suggestion, changing

void upsert(name user) 


void ktc::upsert(name user)

in my .cpp file solved the issue. My header file contained all the declarations and so ktc::upsert worked.

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.