Debugging Smart Contracts¶
If you come from a well-groomed development environment, such as .Net, Java or pretty much anything, you know how important it is to be able to step-by-step debug code.
In Solidity you loose almost all of the luxury you're used to from other languages. But there are still some options available.
Debugging Advanced
If you are looking into a more advanced way to debugging smart contracts, then wait until we use Truffle, or directly head over to the Truffle Debugging section on their website.
Smart Contract¶
Add the following Smart Contract to Remix:
//SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
contract DebuggerExample {
uint public myUint;
function setMyUint(uint _myuint) public {
myUint = _myuint;
}
}
And deploy it to the JavaScript VM:
Interact with the Smart Contract¶
Now lets set the Uint to "5" and hit the little "Debug" button in the Transaction window. You were probably wondering already what that debug button is there for anyways...
It will open up the Remix Debugger, which looks something like this:
You can run through the transaction with the horizontal scroll bar (1), or use the step-by-step button (2). Also observe the actual opcodes that are executed during each step (3):