3

I have created smart contract inside the /build/contracts and running this comman generates empty abi file.

eosiocpp -g eosio.test.abi eosio.test.cpp

tried both hpp and cpp but same result.

5
  • Can you confirm your passing these actions into EOSIO_ABI? Add the code to the question as well perhaps. Commented Jun 25, 2018 at 3:42
  • try to add @abi table or action to your table or function header
    – Jimmy Guo
    Commented Jun 25, 2018 at 14:44
  • Actually the code is based on eosio.token, I'm trying to play around with it. EOSIO_ABI( eosio::test, (create)(issue)(transfer)(hi) )
    – Dominic
    Commented Jun 26, 2018 at 1:18
  • There are lots of developers experiencing this issue, I wonder why and what is the common cause of this issue?
    – Dominic
    Commented Jun 26, 2018 at 1:19
  • I don't think annotations are still necessary if you are using the EOSIO_ABI right?
    – Dominic
    Commented Jun 26, 2018 at 1:23

6 Answers 6

3

I had this happen to me last night. Make sure the class name and your file names match.

In other words, if you're compiling the hello contract, make sure the file names are hello.hpp and hello.cpp.

1
  • ha! that was my problem too
    – ekkis
    Commented May 29, 2019 at 19:11
2

You could use of the newest macros:

Added ACTION macro which is simply a shortcut for [[eosio::action]] void.
Added TABLE macro which is simply a shortcut for struct [[eosio::table]].
Added CONTRACT macro which is simply a shortcut for class [[eosio::contract]].

2
  • why would I want to do that?
    – ekkis
    Commented May 29, 2019 at 19:09
  • 1
    At the time of writing this eosio.cdt wasn't able to compile contracts without the macros. Currently I think it works both ways.
    – Kristian
    Commented Jun 26, 2019 at 5:07
2

When you're generating your ABI consider a few things:

  1. Use the new command eosio-cpp

    For example: eosio-cpp -I include -o my_contract.wasm my_contract.cpp -abigen

  2. Use the C++ 11 attributes included in the newest EOSIO version such as [[eosio::action]], [[eosio::table]], [[eosio::contract]]

  3. If the contract structure is too complicated at this point "abigen" could fail to generate the ABI file. You should create it manually or eventually fix broken parts. Take a look at Understanding ABI Files :)
2

I'm assuming you are using one of the new CDTs

In my case the following command worked

eosio-abigen hello.cpp --contract=hello --output=hello.abi
1
  • odd. that worked for me. you'd think that --abigen would just call this internally and work just as well
    – ekkis
    Commented May 29, 2019 at 19:08
1

you need extra comments marked in hpp file to help eosiocpp generate concrete abi file. for actions, you need to add comment

c++ //@abi action

above its declaration. for multi_index table, you need to add comment

c++ //@abi table <underlying class or struct name> (i64|i32)

above the underlying class or struct definition.

1
  • what is the difference of i64 and i32? The primary key only receive uint64, right?
    – Jimmy Guo
    Commented Jul 27, 2018 at 11:39
0

This may be caused by an invalid contract name. If filename and contract class name do not match, eosio-cpp does not generate the abi.

If your file has the name foobar then your contract must also have the name foobar. If this is not the case you need to specify the -contract=name parameter.

Assuming your file is named foobar.test.cpp and your contract name is foobar, you need to compile with:

eosio-cpp -abigen fooobar.test.cpp -o foobar.wasm -contract=foobar

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.