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?
1 Answer
It is possible:
- Set up a new smart contract environment using
eosio-init
:
eosio-init -project=mycontract -path=.
- Create all of your .cpp and .hpp files as appropriate
- In the ./src folder, edit the
CMakeLists.txt
file by adding all of the.cpp
files to theadd_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 )
- 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