4

I have the contract

class test : public contract {
public:
    using contract::contract;

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

...

private:
    struct test_rec
    {
        test_hash hash;
        account_name creator;

        uint64_t primary_key() const { return hash; }
        account_name get_creator() const { return creator; }
    };

    typedef eosio::multi_index<N(tests), test_rec > tests;
};

So, when I am generating abi file, tables section is empty.

...
"tables": [],
...

What I am doing wrong?

  • I believe you need // @abi table tests i64 above the table – Rogério Richa May 18 '18 at 0:02
  • you should declare @abi table test_rec i64 above your table struct – Nirdesh Kumar Choudhary Oct 5 '18 at 5:21
7

Try the below snippet:

// @abi table tests i64
struct test_rec
{
    test_hash hash;
    account_name creator;

    uint64_t primary_key() const { return hash; }
    account_name get_creator() const { return creator; }

};

typedef eosio::multi_index<N(tests), test_rec > tests;
|improve this answer|||||
  • may i ask you why we need to add "test i64" after "@abi table" ? what is the "test i64" for ? – Harry Ma May 18 '18 at 1:51
  • it's just to force the type of your primary key... in the past sometimes it was getting lost, not sure how the abi generator is now but I always force the primary key type as a safety measurement – Leo Ribeiro May 18 '18 at 2:22
  • 1
    @LeoRibeiro Thanks for your help. But still I cannot understand. Why the examples from eos/contracts doesn't have this semantic? and they are working. – Taras Shchybovyk May 18 '18 at 6:41
  • because maybe the abi generator is fixed. when you have complex types on your primary key field it was returning i64i64i64 which breaks the abi. now it must be fixed.. you can just not use it and when you get the above problem you can force it as I do – Leo Ribeiro May 18 '18 at 8:34
  • @LeoRibeiro why you don't use // abi table test_rec i64 because table is of struct test_rec we typedef your struct later as tests. – Nirdesh Kumar Choudhary Oct 5 '18 at 5:33
0

There are some changes with the latest EOSIO versions. First, use the attributes coming from C++ 11, [[eosio::contract]], [[eosio::action]] and [[eosio::table]].

struct [[eosio::table]] user
{
    uint64_t id;
    string name;
    uint64_t age;
    string address;

    uint64_t primary_key() const { return id; }
};

If the structure is too complex you may need to fix broken parts in the ABI during the generation or manually create the tables in the ABI. Check the link for more information - Understanding ABI Files

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.