1

When I try to compile the contract the process creates an infinite loop. Here is my code, please help!

kjnjrwsyxszg.cpp

#include "kjnjrwsyxszg.hpp"
void kjnjrwsyxszg::create(const name owner, const string name, const uint64_t attack)
{
    // Instantiate items_table
    items_table items(_self, _self.value);

    // Create and set item
    items.emplace(owner, [&](auto &item) {
        item.id = items.available_primary_key();
        item.name = name;
        item.attack = attack;
        item.owner = owner;
    });
}

kjnjrwsyxszg.hpp

#include <eosio/eosio.hpp>
#include <string>

using namespace eosio;
using namespace std;

class[[eosio::contract("kjnjrwsyxszg")]] kjnjrwsyxszg : public eosio::contract
{
public:
    using contract::contract;

    [[eosio::action]] void create(const name owner, const string name, const uint64_t attack);

private:
    // @abi table items i64
    struct [[eosio::table]] Item
    {
        uint64_t id;
        string name;
        uint64_t attack;
        eosio::name owner;

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

    typedef multi_index<"items"_n, Item> items_table;
};
0

not sure if one of these solves your issue but try to leave out the additional "void" and use ACTION instead of [[eosio::action]].

kjnjrwsyxszg.cpp

#include "kjnjrwsyxszg.hpp"
ACTION kjnjrwsyxszg::create(const name owner, const string name, const uint64_t attack)

kjnjrwsyxszg.hpp

using namespace eosio;
...
CONTRACT kjnjrwsyxszg : public contract
{
public:
    using contract::contract;

    ACTION create(const name owner, const string name, const uint64_t attack);
...

The following is wrong, see Phillips comment below

you are also missing the Dispatcher in your .cpp

EOSIO_DISPATCH(kjnjrwsyxszg, (create))
2
  • 1
    EOSIO_DISPATCH is no longer needed in the most recent versions of eosio.cdt. As for using [[eosio::action]] void, there is no difference between this and ACTION, except that using the attributes allows you to give a different name to the action in the ABI file and the function name. For example: [[eosio::action("create")]] void create_character would make an action called create, but in your code you can have a better name like create_character Oct 27 '20 at 6:55
  • 1
    Oh. I've missed that.
    – cmadh
    Oct 27 '20 at 10:58

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.