How to write EOS Smart contracts for version 1.3.0!

in #eos6 years ago

Instrument eosiocpp used to be recommended for the smart contract compliance, provided with EOSIO installation. Despite eosiocpp is still available under the version 1.3.0 of smart contract compiling and .abi files creating, new EOSIO Contract Development Toolkit (EOSIO.CDT) is recommended for further maintenance [this very to be improved in the next releases].

EOSIO Contract Development Toolkit presented in a separate repository. 

Follow the following steps to install:

git clone --recursive https://github.com/eosio/eosio.cdt

cd eosio.cdt

To run build and set all the necessary correlation one needs to specify CORE_SYMBOL EOSIO blockchain at a start. You shouldn’t use EOS name by default when starting a test network, just run ./eosio_build.sh [CORE_SYMBOL  SYS. By default] You could check CORE_SYMBOL_NAME in the file  «CMakeLists.txt»]. CORE_SYMBOL can be setup by EOSIO action from Software Directory [bydefaultactioneos]  ./eosio_build.sh -s EOS [is used for Jungle Testnet].

    ./build.sh SYS    или    ./build.sh  EOS  

--this process may take a long while.

Installation core eosio.cdt into directory /usr/local/eosio.cdt and symlinks on the instruments of /usr/local/bin for better workout

    sudo ./install.sh


Main toolkit for interaction eosio-cpp  --  C ++ compiler

eosio-cc   -- C compiler

eosio-ld  -- linker

eosio-abigen – ABI generator.


To compile source .cpp file of your smart contract into.wasm format and generate .abi you can do in one step [from that very directory.cpp file is through setting its way] 

eosio-cpp new_contract.cpp -o new_contract.wasm --abigen

An option --abigen, will specify eosio-cpp to run eosio-abigen after [without this option file new_contract.wasm will be created only]. If an output file is indicated as .wasm with parameters -o (e.g., new_contract.wasm), then eosio-cpp will report to ABI of the file creation with the same .abi name.   

That step will create two files new_contract.wasm and new_contract.abi


In contrast to the eosiocpp generator ABI, eosio-abigen has style attributes C++11 and GNU to declare actions and tables, that is, before .abi file generation, you need to mark all the actions and tables in the file.cpp by the following means.


Means of declaring an action for ABI generation:

[[eosio::action]]

void action_name( account_name user ) {

// something

}


__attribute__((eosio_action)) 

void action_name( account_name user ){

    // something

}


Means of declaring table for ABI generation:


struct [[eosio::table]] table_name {

    uint64_t account_name;

      /*other fields */

};


struct __attribute__((eosio_table)) table_name {

    uint64_t account_name;

        /* other fields */

};


You should specify EOSIO_ABI at the end of the file, to transfer class name of the smart contract, and all the actions. Thus you make .cpp file compatible with the shell ISM EOSIO by adding this info.

    EOSIO_ABI( class_name, (action1)(action2)(action3) )


Note: file ABI, generated through eosio-abigen, may not be strictly correct. Further checkups, control and corrections of .abi file will make your smart contract function correctly.  

Deploy & Update is similar to the previous one.

 Follow us!

Website: https://attic.tech/

Twitter: https://twitter.com/atticlab_it

Facebook: https://www.facebook.com/atticlab/

Reddit: https://www.reddit.com/r/atticlabeosb/

Steemit: https://steemit.com/eos/@attic-lab

Medium: https://medium.com/eosatticlab

Golos: https://golos.io/@atticlab

Telegram Chat: https://t.me/atticlabeosb

Telegram channel: https://t.me/eos_atticlab

Github: https://github.com/atticlab