I have been fighting a bit with the EOSIO_ABI
macro in C++. I am trying to implement a very simple Ping/Pong contract using the latest eosio.cdt
tools installed on my machine.
When I try to compile the following code:
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using eosio::name;
using eosio::print;
class ping_contract : public eosio::contract
{
public:
using eosio::contract::contract;
/// @abi action
void ping(name receiver) {
eosio::print("Pong from ", name{receiver});
}
};
EOSIO_ABI(ping_contract, (ping))
It ends in the following error messages :
$ eosio-cpp -o tests/ping/ping.wasm tests/ping/ping.cpp --abigen
tests/ping/ping.cpp:19:27: error: C++ requires a type specifier for all declarations
EOSIO_ABI(ping_contract, (ping))
^
tests/ping/ping.cpp:19:33: error: expected function body after function declarator
EOSIO_ABI(ping_contract, (ping))
^
2 errors generated.
I tried out multiple syntax things, like using the CONTRACT
keyword instead of class
, or using the ACTION
keyword in front of the ping()
action.
There is actually 2 problems which I have here. First of all, it is required for me to write the ABI myself, then the real error, is about this EOSIO_ABI macro not functioning, as this is obviously the important part.
On another front, I have tested out using the EOSIO_DISPATCH
macro instead of the EOSIO_ABI
macro, with that one, the code compiles correctly. And I can also cleos push action ...
. Yet, I don't see the eosio::print
being executed. Though, I see a transaction appearing in blocks.
Please any help would be appreciated here :+1:
$ eosio-cpp -version
eosio-cpp version 1.3.2
$ g++ --version
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.0.0
Have a great evening! :)