How to Debug Ethereum Smart Contract

Table of Contents

Read Time: 5 minutes

Debugging a smart contract transaction in the blockchain is different from debugging a traditional application build on c++ or JavaScript as you are not running code in real time, instead of in blockchain, historic transaction execution is mapped with the associated code to debug a transaction.

A Smart contract is a piece of code run on the top of the blockchain, smart contracts need to make sense in a precise manner, debugging a Smart contract is analyzing a transaction step by step how functions internally work and proceed or where the actual transaction has failed.

Let us discuss first types of error in solidity in detail to debug transaction.

Types of Error in solidity  –

1. Syntax Error

A syntax error arises when there is a problem in a syntax of smart contract code when your code strike with syntax error your smart contract will not be able to compiled or deployed on the blockchain.

Syntax error can be easily diagnosed using remix, as you can see in the picture below, when semicolon(;) is removed from the above code in remix IDE, it displays an error message with solution of syntax error.

Syntax error can be easily diagnosed using truffle, remix or any IDE.

2. Run time Error

Run time errors arises only when you have deployed a smart contract to blockchain and your solidity code has been compiled to bytecode that has been understood by EVM (Ethereum virtual machine). EVM is defined as a component of Ethereum that runs solidity code and run time error arises when EVM thinks that you are doing something wrong with your smart contract code or you are making transaction against the logic of the code.

Run time errors are more difficult to diagnose than syntax error because these errors are not identified before deploying on blockchain, they can only arise when state change takes place in smart contract, we will discuss more run time errors and debugging of run time errors in details.

3. Logic Errors

Logic errors cannot be debugged using any IDE or tool, because logic errors are not captured by EVM, according to EVM everything is perfect and code can be run easily. the logic error arises when a developer makes a mistake and open loopholes in a smart contract for attackers.

Example of Logic Error: Famous DAO attack(Reentrancy) is an example of a logic error where the developer made a mistake and transferred either before updating the balance of the user.

Logical errors can be identified by Audit of smart contract because sometimes according to developer’s mindset everything is going well and there may not be an error in smart contract but an Auditor can run a smart contract with the intent to find loopholes, check business logic and to find security flaws in smart contract.

Formal Verification may come into use for logic verification of smart contract.

Types of Run time error

Out of Gas

Out of gas error occurs when you don’t provide enough gas to execute a transaction, or gas is not enough to complete a transaction.


Transaction revert will occur when you are trying to execute a transaction that cannot be executed according to the logic of smart contract hence EVM will return an error and transaction is reverted.

Invalid opcode

Invalid opcode occurs when you are trying to call a code that doesn’t exist.

Invalid Jump

The invalid jump occurs when you are trying to call a function that doesn’t exist, for example, if you call a function of contract via another contract that doesn’t exist, an invalid jump occurs. This type of error also occurs when you use assembly language and you point to wrong memory.

Stack Overflow

Stack Overflow occurs when you are trying to call the function recursively and there is no condition to stop it, in solidity stack can be at most 1024 frame, so a function can call itself only 1024x times if you exceed that Stack Overflow will occur.

Stack Underflow

Stack underflow occurs in assembly language when you try to pop a variable that doesn’t exist.

Sample Smart Contract code to be used in debugging all types of errors and transactions-

pragma solidity 0.4.24;
contract Sample {
   uint256 public amountInContract;
   address public amountOwner;
  constructor(address _owner) public payable {
     require(_owner != address(0));
     require(msg.value > 0.1 ether);
     amountInContract = msg.value;
     amountOwner = _owner;
 function () external{
function withdraw () public {

The debugger provides the ability to debug any transaction (creation or call) step by step and to visualize the memory/storage space. It helps to trace the gas cost by the opcode and the remaining gas after each step.

Debugging a transaction-

In above code as specified constructor is payable while deploying a contract constructor required sending ether value above 0.1 ethers. If less than 0.1 ether is sent or address is zero, it will throw an error and transaction will be reverted.

As shown below, the transaction is reverted so we will debug a transaction step by step using remix IDE.

Step 1. After deployment transaction is submitted to Ethereum blockchain using remix, the transaction is failed as shown above. Now press the debugger button in remix IDE to debug the transaction and to find out the possible reason for transaction failure.

Step 2. To start debugging, provide block number and transaction hash and press the start debugging button this will start the debugging process.

Assembly language operations along with with the gas used and remaining gas are displayed while debugging a transaction, as shown above, also the code is highlighted in remix IDE where actual transaction failed parallel to opcode as shown below.

The transaction is reverted in assembly opcode. The code is highlighted where actual transaction reverted.

As shown in the above picture where transaction is reverted in etherscan the value sent is 0.1 ether, that is less than the required value; that is why the transaction failed in this scenario.

This process can be used to debug any transaction to know more about the gas used, remaining gas at each step, state changes and to visualize memory/storage space.

Smart contract debugging can also be done using truffle framework, you need a transaction hash to debug a transaction.

Launch your blockchain project with Quillhash:

At QuillHash, we understand the Potential of Blockchain and have a good team of developers who can develop any blockchain applications like Smart Contracts, dApps,Smart Coins, DeFi, DEX on the any Blockchain Platform like EthereumEOS and Hyperledger.

To be up to date with our work, Join Our Community :-

Telegram | Twitter | Facebook | LinkedIn


Related Articles

View All



Description: This type of security vulnerability can occur when untrusted data is used in a smart contract without proper validation or sanitization, allowing an attacker to execute unauthorized functions or modify the state of the contract.


QuillAudits 🤝 Lovely Launchpad

We are pleased to extend our #partnership with Lovely Launchpad and await great possibilities to secure the #Web3 ecosystem & beyond.

More About Lovely Launchpad:

#web3community #collaboration

As Web3 developers, it's critical to prioritize smart contract security to protect users' funds and maintain the integrity of the blockchain.

Threat modelling and Risk assessment are two key processes that can help identify potential risks and…


@safemoon has been exploited due to a public burn issue with around ~$8.9 M loss.

With the exploited public burn bug, the upgrade was initiated by the official SafeMoon: Deployer.

Load More

Amidst FTX Saga, Hacker Swept More Than $25 Million in 2nd week of November

The contract reinvested (the earn function was not called) before the user pledged (depositAll function) without settling the reward, which means that when the user pledged, the contract did not settle the previous reward and instead conducted a new investment.

Become a Quiffiliate!
Join our mission to safeguard web3

Sounds Interesting, Right? All you have to do is:


Refer QuillAudits to Web3 projects for audits.


Earn rewards as we conclude the audits.


Thereby help us Secure web3 ecosystem.

Total Rewards Shared Out: $190K+