How to Debug EOSIO based Smart Contract?
To debug a EOS based smart contract, developers are required to firstly setup a local node using nodeos. This local node can take be designated to run as a separate private testnet or as an extension of public testnet. This local node also needs to be run with the contracts-console option on, either
--contracts-consolevia the command line or
contracts-console = true via the config.ini and/or by setting up logging on your running nodeos node and checking the output logs.
To setup local node as a private testnet, follow the setup guide. By default, your local nodeos will run in a private testnet.
To configure local nodeos as an extension public testnet, you need to modify the config.ini file to connect with public testnet nodes.
This is the main method to debug smart contract that utilizes the printing functionality to inspect the value of a variable and the flow of the contract. Printing in smart contract can be done through the print API.
Print C API supports the following data type that can print:
· Prints — a null terminated char array (string)
· prints_l — any char array (string) with given size
· printi — 64-bit signed integer
· printui — 64-bit unsigned integer
· printi128–128-bit signed integer
· printui128–128-bit unsigned integer
· printsf — single-precision floating point number
· printdf — double encoded as 64-bit unsigned integer
· printqf — quadruple encoded as 64-bit unsigned integer
· printn — 64 bit names as base32 encoded string
· printhex — hex given binary of data and its size
Code examples can be found here: https://developers.eos.io/eosio-cpp/docs/debugging