...by Daniel Szego
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Wednesday, April 4, 2018

Solidity Tips and Tricks - debug mode with simple switch

Well, designing a smart contract is pretty tricky, basically the contract is immutable so basically it is not upgradable, even if you use some direct patterns for update. So what you can basically do is to build in some debug functionalities, like getting extra debug information or updating parts of the system in a debug mode... The most simple way how you can control such a debug mode is to have a bool switch called debugMode that can be set true only once at the go live causing that the debug functionalities will not be accessible anymore. An example can be seen on the following code:

contract TestDebugMode {
 bool public debugMode = true ; 
   function goLive(){
      debugMode = false;

   modifier isInDebug(){
      require(debugMode == true);        

   function onlyInDebug() isInDebug {


Certainly, a real smart code might be somewhat more difficult, as it has to be guaranteed that only an owner or an administrator can deactivate the debug mode by going live.