0

As i was following eosio developers documentation

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

using namespace eosio;
using namespace std;

class addressbook : public contract {

public:
  using contract::contract;

  addressbook(account_name self): contract(self) {}

  [[eosio::action]]
  void upsert(account_name user,  string first_name,  string last_name,  string street,  string city,  string state) {
    require_auth( user );
    address_index addresses(_self, _self);
    auto iterator = addresses.find( user );
    if( iterator == addresses.end() )
    {
      addresses.emplace(user, [&]( auto& row ) {
       row.key = user;
       row.first_name = first_name;
       row.last_name = last_name;
       row.street = street;
       row.city = city;
       row.state = state;
      });
    }
    else {

      addresses.modify(iterator, user, [&]( auto& row ) {
        row.key = user;
        row.first_name = first_name;
        row.last_name = last_name;
        row.street = street;
        row.city = city;
        row.state = state;
      });
    }
  }

  [[eosio::action]]
  void erase(account_name user){
    // require_auth(user);
    address_index addresses(_self, _self);
    auto iterator = addresses.find( user );
    eosio_assert(iterator != addresses.end(), "Record does not exist");
    addresses.erase(iterator);
  }

private:
  struct [[eosio::table]] person {
    account_name key;
     string first_name;
    string last_name;
     string street;
    string city;
     string state;
    uint64_t primary_key() const { return key; }
  };
  typedef eosio::multi_index<N(people), person> address_index;

};

EOSIO_ABI( addressbook, (upsert)(erase) )

after executing following command ,I got

cleos get table addressbook addressbook person -k alice

     Error 3060003: Contract Table Query Exception
Most likely, the given table doesn't exist in the blockchain

1 Answer 1

0
typedef eosio::multi_index<N(people), person> address_index;

Check that the name of table you are providing N(people), but you are executing

cleos get table addressbook addressbook person -k alice

you should be executing

cleos get table addressbook addressbook people -k alice

If you find any issue check the abi file generated for debugging.

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.