I am using Ubuntu 18.04 LTS first of all.
So I am trying to look up how to start building an EOS dApp, starting with this example on Github.
Here is the link: https://github.com/eosasia/eos-todo
I cloned the repository and tried to run it by deploying the todo.cpp file which is inside the contract folder.
The whole code for todo.cpp is here:
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
class todo_contract : public eosio::contract {
public:
todo_contract(account_name self)
:eosio::contract(self),
todos(_self, _self)
{}
// @abi action
void create(account_name author, const uint32_t id, const std::string& description) {
todos.emplace(author, [&](auto& new_todo) {
new_todo.id = id;
new_todo.description = description;
new_todo.completed = 0;
});
eosio::print("todo#", id, " created");
}
// @abi action
void destroy(account_name author, const uint32_t id) {
auto todo_lookup = todos.find(id);
todos.erase(todo_lookup);
eosio::print("todo#", id, " destroyed");
}
// @abi action
void complete(account_name author, const uint32_t id) {
auto todo_lookup = todos.find(id);
eosio_assert(todo_lookup != todos.end(), "Todo does not exist");
todos.modify(todo_lookup, author, [&](auto& modifiable_todo) {
modifiable_todo.completed = 1;
});
eosio::print("todo#", id, " marked as complete");
}
private:
// @abi table todos i64
struct todo {
uint64_t id;
std::string description;
uint64_t completed;
uint64_t primary_key() const { return id; }
EOSLIB_SERIALIZE(todo, (id)(description)(completed))
};
typedef eosio::multi_index<N(todos), todo> todo_table;
todo_table todos;
};
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
I tried to build wast and abi file from it for the first step but there are 4 errors coming up when I type
eosio-cpp -o todo.wast todo.cpp && eosio-cpp -g todo.abi todo.cpp
in the Terminal.
The 4 errors I have got are:
todo.cpp:57:40: error: unknown type name 'complete'
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
^
todo.cpp:57:50: error: unknown type name 'destroy'
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
^
todo.cpp:57:32: error: C++ requires a type specifier for all declarations
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
^
todo.cpp:57:59: error: expected function body after function declarator
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
^
4 errors generated.
I have googled many times but could not find the solution yet.
Any help I can use about this problem? Thanks in advance!
todo.cpp:9:10: error: no matching constructor for initialization of
'eosio::contract'
:eosio::contract(receiver, code, ds),
^ ~~~~~~~~~~~~~~~~~~
/usr/local/eosio.cdt/bin/../include/eosiolib/contract.hpp:26:7: note: candidate
constructor not viable: requires single argument 'n', but 3 arguments were
provided
contract( account_name n ):_self(n){}
^
/usr/local/eosio.cdt/bin/../include/eosiolib/contract.hpp:18:7: note: candidate
constructor (the implicit copy constructor) not viable: requires 1
argument, but 3 were provided
class contract {
^
/usr/local/eosio.cdt/bin/../include/eosiolib/contract.hpp:18:7: note: candidate
constructor (the implicit move constructor) not viable: requires 1
argument, but 3 were provided
todo.cpp:10:27: error: member reference base type 'account_name' (aka
'unsigned long long') is not a structure or union
todos(_self, _self.value)
~~~~~^~~~~~
todo.cpp:58:40: error: unknown type name 'complete'
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
^
todo.cpp:58:50: error: unknown type name 'destroy'
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
^
todo.cpp:58:32: error: C++ requires a type specifier for all declarations
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
^
todo.cpp:58:59: error: expected function body after function declarator
EOSIO_DISPATCH(todo_contract, (create)(complete)(destroy))
^
6 errors generated.
These 6 errors are the new errors I have got right now.
eosio-cpp
. The classeosio::contract
with constructorcontract(account_name n)
belong toeosiocpp
, deprecated old compiler. Have you installed eosio.cdt?