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?

2
  • I believe you need // @abi table tests i64 above the table Commented May 18, 2018 at 0:02
  • you should declare @abi table test_rec i64 above your table struct Commented Oct 5, 2018 at 5:21

2 Answers 2

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;
6
  • may i ask you why we need to add "test i64" after "@abi table" ? what is the "test i64" for ?
    – Harry Ma
    Commented May 18, 2018 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 Commented May 18, 2018 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. Commented May 18, 2018 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 Commented May 18, 2018 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. Commented Oct 5, 2018 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

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.