When developing my smart contract, how can I debug it? Are there any debugging, testing tools or simulators that I can use to examine my code?
Those are all good tools, but I have found the logging events is much easier method for debugging, plus if you are doing anything with money you want to keep a record of what happened.
This is how I debug my (currently) 780 lines of solidity.
to debug a contract you could use the solidity browser
the debugger provides you the ability to debug any transaction (creation or call) step by step and to visualize the memory/storage space. it helps you to trace the gas cost by opcode and the remaining gas after each step.
To debug transactions, there's two way of doing that:
2-using a transaction hash.
The debugger itself contains several controls that allow stepping over the trace and seing the current state of a selected step.
Slider and Stepping action:
The slider allows to move quickly from a state to another. Stepping actions are:
Step Into Back Step Over Back Step Over Forward Step Into Forward Jump Next Call (this will select the next state that refers to a context changes - CALL, CALLCODE, DELEGATECALL, CREATE) State Viewer:
The upper right panel contains basic informations about the current step:
VMTraceStep: the index in the trace of the current step. Step Add memory Gas: gas used by this step Remaining gas: gas left Loaded address: the current code loaded, refers to the executing code. The other 6 panels describe the current selected state:
Instructions list: list of all the instruction that defines the current executing code. Stack Storage Changes Memory Call Data$ Call Stack
You can use
truffle debug command: http://truffleframework.com/blog/announcing-full-portable-solidity-debugger
- Code stepping (over, into, out, next, instruction, etc.)
- Current code location, including the address of the running contract
- Watch expressions
- Variable inspection (stack, memory and storage)
- Custom expression evaluation using Solidity variables
latest version truffle has an inbuilt debugger that can be used to debug state of a failed transaction.
$ truffle debug <transaction-id>
<transaction-id> is id of the errored transaction,
once debugger is launched follow the instruction to walkthrough and print variable state etc
find out more here : https://www.trufflesuite.com/blog/announcing-full-portable-solidity-debugger
I recently released a public beta of my Solidity Debugger, which is a Visual Studio Code extension. It integrates with the Hardhat framework and allows you to step through solidity smart contracts. Check it out here: https://soliditydebugger.org/