1

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! :)

3

Problem solved ! I didn't go through the CHANGELOG for the latest 1.2 to 1.3 upgrade.

It turns out, the EOSIO_ABI macro has been renamed EOSIO_DISPATCH and so, it seems there is no problem with compilation on my machine.

One thing is remaining, but is linked to ABI generation, for which I took the decision to write it manually.

| improve this answer | |
  • Where did you see this in the change log? I'm looking through the GitHub release history, but I don't see it. – Jason Bert Nov 6 '18 at 10:57
  • hey there, you can see it here: github.com/EOSIO/eosio.cdt#eosiolibdispatcherhpp – Greg eVias Nov 6 '18 at 14:49
  • if you want automatic ABI generation, look at the ACTION, CONTRACT, and TABLE macros in eosio.cdt. They wil make sure your methods and tables are properly marked for inclusion in the ABI. – John Haager Nov 8 '18 at 23:06

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.