Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Solidity Programming Essentials

You're reading from  Solidity Programming Essentials

Product type Book
Published in Apr 2018
Publisher Packt
ISBN-13 9781788831383
Pages 222 pages
Edition 1st Edition
Languages

Table of Contents (17) Chapters

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Introduction to Blockchain, Ethereum, and Smart Contracts Installing Ethereum and Solidity Introducing Solidity Global Variables and Functions Expressions and Control Structures Writing Smart Contracts Functions, Modifiers, and Fallbacks Exceptions, Events, and Logging Truffle Basics and Unit Testing Debugging Contracts Other Books You May Enjoy Index

Chapter 10. Debugging Contracts

This is the last chapter of the book. By now, we have looked at Solidity and Ethereum from a conceptual standpoint, developed and authored Solidity contracts, and tested them. The only thing that was not discussed was troubleshooting contracts. Troubleshooting is an important skill and exercise when dealing with any programming language. It helps in finding issues and solving them efficiently. Troubleshooting is both an art and a science. Developers should learn the art of troubleshooting through experience as well as by exploring details behind the scenes using debugging. This chapter will focus on debugging coding issues related to Solidity contracts.

This chapter covers the following topics:

  • Debugging contracts
  • Debugging contracts using Remix and Solidity events

Debugging


Debugging is an important exercise when authoring Solidity smart contracts. Debugging refers to finding issues, bugs, and removing them by changing code. It is very difficult to debug a smart contract if there is in adequate support from tools and utilities. Generally, debugging involves executing each line of code step by step, finding the current state of temporary, local, and global variables and walking through each instruction while executing contracts.

There are the following ways to debug Solidity contracts:

  • Using the Remix editor
  • Events
  • Block explorer

The Remix editor

We used the Remix editor to write Solidity contracts in the previous chapters. However, we have not used the debugging utility available in Remix. The Remix debugger helps us observe the runtime behavior of contract execution and identify issues. The debugger works in Solidity and the resultant contract bytecode. With the debugger, the execution can be paused to examine contract code, state variables, local variables...

Using a Block Explorer


A Block Explorer is an Ethereum browser. It provides reports and information about current blocks and transactions in its network. It's a great place to learn more about existing and past data. It is available at https://etherscan.io/, as shown in the following screenshot:

It shows transactions involving both accounts and contracts. Clicking on a transaction shows details about it, as shown in the following screenshot:

By now, you understand the details about transactions stored within the Ethereum ledger. From the preceding screenshot, let's take a look at the following few details of the transaction:

  • TxHash: This detail refers to transaction hashes
  • TxReceipt Status: This detail represents the status of a transaction, whether successful or pending
  • Block Height: This detail shows which block number the transaction is stored in
  • TimeStamp: This detail shows the timestamp for the transaction
  • From: This detail shows who sent the transaction
  • To: This detail shows the recipient...

Summary


This brings us to the end of this chapter and this book. Solidity is a new programming language that is evolving continuously. Solidity contracts can be debugged using the Remix editor. Remix provides a convenient way to author and debug contracts by verifying variables and code execution at every step. It helps us move forward and back in code execution. It provides breakpoints to break the execution of code. There are other ways to debug contracts as well. These include using Block Explorers and Solidity events. Although events and Block Explorers provide limited capabilities for debugging, they are very helpful and facilitate production.

I hope you enjoyed reading this book and sincerely believe that you are becoming a rock star Solidity developer by now. Stay tuned and keep learning!

 

lock icon The rest of the chapter is locked
You have been reading a chapter from
Solidity Programming Essentials
Published in: Apr 2018 Publisher: Packt ISBN-13: 9781788831383
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}