1

If we want to make our smart contract code modular, and keep each class, contract, and table in its own file, is it possible to do this, and if so, how?

2

It is possible:

  1. Set up a new smart contract environment using eosio-init:

eosio-init -project=mycontract -path=.

  1. Create all of your .cpp and .hpp files as appropriate
  2. In the ./src folder, edit the CMakeLists.txt file by adding all of the .cpp files to the add_contract command, making sure that the file containing your contract class is the last file in the list:

add_contract( mycontract mycontract table.cpp helper.cpp mycontract.cpp )

  1. If you have a table in its own file, and it isn't a member of the contract class, then it will not be included in the ABI file unless you indicate that it needs to be included in the contract in your attributes:

class [[eosio::table, eosio::contract("mycontract")]] mytable

| improve this answer | |

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.