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