cleos, it is now time for us to build our first Telos smart contract!
cd helloWorldinto the folder.
eosio-init -project helloWorld. This will create the basic source code needed to create a simple "hello world" smart contract that we will be able to publish onto the blockchain. The name of the contract is determined by the term following the
-projecttext, so our contract will be entitled
helloWorld. The basic folder structure should look something like the following:
build: this is where the compiled final files will be generated that we will push to the blockchain. The folder should start off empty
include: the header files that will be referenced in the C++ source code
ricardian: this folder is for Ricardian Contracts, which are outside of the scope of this tutorial, but are typically used in parallel with smart contracts to help clarify the contract's intent. We will ignore this folder for now.
src: the source C++ files that will dictate the behavior (actions) of our smart contract. It also starts off with a
CMakeLists.txtfile which helps to configure the compilation process (this file can be ignored for now)
README.txt: directions on how to build and publish the smart contract
src/helloWorld.cpp. Let's start with the header file:
eosio/eosio.hppheader file that includes many tools that will make our lives easier. It then uses the
eosionamespace to make our syntax cleaner. The contract
helloWorldis a class extending the
eosio::contractclass. Inside of the class we use the
eosio::contract::contractnamespace and then declare the action
hiwhich will take in a parameter
name. Note that the
ACTIONsyntax is a macro imported from the
eosio/eosio.hppand represents a type of function.
helloWorldclass. Again, the
ACTIONsyntax is a macro for a function. The method takes in
nmwhich is of type
name. Inside of the method, a simple string
Name : someNameis printed to the console output for any full node that processes this smart contract action.
brew install make && brew install cmakefor MacOS and
sudo apt-get -y install cmakefor Ubuntu. Once they are installed, navigate to the
cd buildand then
cmake .. && make ... You should then see the following folders created within the
cleos set contractand the documentation we have for it is the following: