2

This is my sample code. Tables are not generated when I compile the contract. Whats wrong?

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


using namespace eosio;
using std::string;

class test1: public contract {


    public:

    using contract::contract;
    test1(name receiver, name code,  datastream<const char*> ds):contract(receiver, code, ds) {}


        [[eosio::action]]
      void hi( name user ) {
         print( "Hello, UEL , nice to meet you", user);
      }

  private:
  struct [[eosio::table]] person {
    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<"people"_n, person> address_index;

};

EOSIO_DISPATCH(test1,(hi));

The output is

{
    "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Tue Dec  4 00:55:47 2018",
    "version": "eosio::abi/1.1",
    "structs": [
        {
            "name": "hi",
            "base": "",
            "fields": [
                {
                    "name": "user",
                    "type": "name"
                }
            ]
        }
    ],
    "types": [],
    "actions": [
        {
            "name": "hi",
            "type": "hi",
            "ricardian_contract": ""
        }
    ],
    "tables": [],
    "ricardian_clauses": [],
    "variants": [],
    "abi_extensions": []
}

1 Answer 1

1

Update the syntax for instantiating the class to the new format:

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


    public:

    // using contract::contract; // older syntax

In order to use the table, you'll need to declare a variable of the table's type below the typdef. For that to work, you'll need to add the name of that table to the class constructor.

  // added table to constructor
  test1(name receiver, name code,  datastream<const char*> ds):contract(receiver, code, ds), _persons(receiver, code.value) {}

  typedef eosio::multi_index<"people"_n, person> address_index;
  // added table declaration so you can use table
  address_index _persons;
};

EOSIO_DISPATCH(test1,(hi));

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.