Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage Articles Book Review: Solidity Programming Essentials

Book Review: Solidity Programming Essentials

Key Takeaways

  • For developers who are new to ethereum and solidity development, there are many unique concepts that need to be learned. These concepts include mining, payable and fallback functions, usage and gas consumption, amongst many others. These techniques generally differ from your traditional development paradigms, in part due to the transfer of value from one account to another and the use of smart contracts.
  • Exception handling continues to improve through the deprecation of the throw statement and the introduction of require, revert and assert statements.
  • Due to the nature of how ethereum transactions are processed, events not only keep stakeholders informed of transaction state, but also aid administrators in the ability to detect and halt the execution of malicious transactions. 

Ethereum is an emerging technology that promises the ability to disintermediate many traditional approaches to business through decentralized ledger technology, built upon open-source software. A key capability of the ethereum blockchain is the ability to write smart contracts that govern the rules of a specific business process and eliminate the need for centralized participants.
There are a few programming language options when writing smart contracts, with the most popular programming language being solidity. As ethereum continues to evolve, the need for documentation and sample implementations becomes even more important.

In the Solidity Programming Essentials book, Ritesh Modi walks developers through many of the core ethereum development concepts including installing ethereum and solidity, explaining data types and variables, writing smart contracts and functions, defining exception handling and events, testing using truffle, and debugging smart contracts.

This book includes hands-on examples that allow developers to experience the concepts that are being discussed. It also introduces and provides demonstrations of many popular ethereum tools including MetaMask, Mist, Remix and ganache-cli.

The Solidity Programming Essentials book was published by Packt in April, 2018. You can preview this book on the Packt website.

InfoQ had the opportunity to interview the author, Ritesh Modi, about this book. Here is what he had to say:

InfoQ: Thank-you for agreeing to this interview, Ritesh. For the benefit of our audience, can you please introduce yourself?

Ritesh Modi: I would like to thank you for having me here. Just to introduce myself – I am Ritesh Modi, a hard-core techie and a geek. I am an ex-Microsoft Senior technical Evangelist. I have been given the honorary title of microsoft regional director and lead for Microsoft Certified Trainers. What it means is that I help provide both Microsoft as well as the developer community with feedback, updates, create proof-of-concepts, and ensure that the community and Microsoft are in sync with each other. Having more than 15 years of experience in industry, I ensure to impact this knowledge to communities and developers at large.

InfoQ: Why did you decide to write this book, and how do you feel readers will benefit from reading your book?

Modi: I was introduced to blockchain, ethereum and solidity during my tenure at Microsoft and was quite intrigued by this technology. I started playing with this technology while helping my customers. I do not even know when I became go engrossed and involved but it happened on its own. I am one the first adopters in India. I quickly realized that solidity is a new programming language and a new paradigm called Contract based programming. There was not much documentation available on internet apart from the official documentation which could be challenging for any newcomer to understand. Also, books on ethereum only fleetingly touch upon this programming language without going into any depth. This was a good enough reason for me to write this book to ensure developers could understand, benefit and write smart contracts effectively and efficiently.

InfoQ: For whom is this book intended?

Modi: The book is primarily intended for developers who want to get started writing quality contracts on ethereum and other platforms supporting this language. However, it is not limited to only developers. Anybody getting started on ethereum will sooner or later have to understand this programming language. This is applicable to architects, engineers, consultants, entrepreneurs and general blockchain communities.

InfoQ: Which chapter did you enjoy writing the most and why?

Modi: One of the favorite chapters in the book is the one that deals with variables in solidity. Solidity has the unique concept and implementation of Storage and Memory variables which I have not come across in other programming languages. Also, there are concepts like reference and values types intertwined with them. At first glance, and for any new-comer, they can be a bit of a difficult topic to understand. However, I think they have been explained in the book in an easy-to-comprehend manner.

InfoQ: For developers who are just getting started with solidity and ethereum, what are some of the initial obstacles that they are going to encounter?

Modi: Blockchain, ethereum and solidity are new paradigms in technology, and as such, understanding their nuances is extremely important. Developers generally come with their existing knowledge and thought process which generally becomes a hinderance in understanding this completely new way of thinking technology. Solidity, being a contract-based programming language, does not come intuitively to developers. This is one of the biggest obstacles for developers. There are unique concepts like payable, fallback functions, usage and consumption of Gas, transfer of value from one account to another, and many more inbuilt into the language and smart contracts. 

InfoQ: The ethereum eco-system continues to evolve and new tools are constantly being introduced. For example, upon reading your book, I learned about new tools like Remix and ganache-cli. What advice do you have for readers on keeping up-to-date with all of the platform and tooling investments being made in ethereum?

Modi: Ethereum and solidity are emerging technologies, platforms and programming languages. I would say they are still in their infancy as of this writing and there is a long way to go in future. The tools and related ecosystem are also building steadily as time travels around them. However, there is immense scope. For example, there is no proper de-compiler for bytecode to generate back the solidity contract. I would recommend readers to subscribe to some of the important blogs and websites related to solidity and ethereum. This includes the website, joining monthly ethereum calls conducted by ethereum team, and staying updated with sites like Medium, Reddit and InfoQ.

InfoQ: One of the benefits of solidity is that it is considered to be Turing Complete. However, it is still relatively immature compared to other languages like Java and C#. What are some areas in solidity that you feel can be improved in order to lower the barrier of entry for new developers, and making existing solidity developers more productive?

Modi: As mentioned before, solidity in an emerging language and is getting richer in terms of functionality with every passing week. In fact, the current stable compiler has reached version 0.4.25 from around 0.4.12 in less than a year. There are areas that can be improved in solidity like string management and manipulation, richer application binary interface to be able to send and receive richer arguments and parameters, exception handling, looping with mappings, and richer datatypes.

InfoQ: Since blockchain transactions are immutable, exception handling becomes a very important activity. As of Solidity 0.4.13, the throw statement is obsolete and assert, and require and revert statements should be used to manage error handling scenarios. Do you feel these strategies are enough to build robust smart contracts? Any advice you want to provide to solidity developers on managing exceptions?

Modi: Throw was deprecated in Solidity 0.4.13 and was replaced with require, revert and assert statements. Throw had lots of limitations, like it used to consume entire supplied Gas. Require helps in ensuring that only needed gas is consumed and rest is returned to the caller. These statements are a significant advancement in solidity language from exception handling and validation perspective. However, there are still possibilities to introduce more exception handling constructs like try-catch-finally blocks, catching specific exception, global contract level exception handling and more.

InfoQ: Events provide a mechanism for dependent applications to be informed that a data or system change has taken place without having to regularly query the ethereum distributed ledger. What are some scenarios where developers can use events in their ethereum projects?

Modi: If you understand ethereum transactions well enough, you would know that transactions are fire and forget in their execution. What this means is that once an account sends a transaction, it does not have to wait for the transaction to complete as the transaction has to be mined, written into blocks and eventually to ledger. This can take some time and callers should not be holding to resources just waiting for it to be complete. Moreover, the execution of the transaction acts like a black-box for the account holders, administrators and operations teams. To get insights into the execution of transactions, developers typically add and invoke events in contracts, that help in logging information to the block. Furthermore, anybody interested in knowing the details about this execution can write code to query this log and get necessary information. This ensures that stakeholders are aware of transaction execution status and details in Ethereum. Events are very important from operations and a security point of view. In case of an attack from a hacker, events can ensure that a message is passed to the administrator and that he can halt the execution of the smart contract; an administrator can get the health and execution status of blocks and transactions using events. 

InfoQ: As the Ethereum blockchain continues to grow and mature, where do you see the ethereum blockchain headed and what are you most excited about as it evolves?

Modi: Ethereum is one of the most serious, stable and proven public and private blockchain today. A lot of companies have already started using it and there is a very active community of miners, developers and investors associated with it. The ethereum organization itself is very active and is always striving hard to bring newer innovation to the platform. Already newer changes for the better, like Proof of stake consensus, sharding, faster sync and higher transactions per second, are planned for the coming months. I am super excited to see the new consensus proof of stake and sharding working and I personally feel that this is and will remain the go-to blockchain platform in future.

About the Book Author

Ritesh Modi is an ex Microsoft senior technology evangelist and Microsoft regional lead. He has worked on ethereum and solidity extensively, helping and advising  companies. Modi is a regular speaker on blockchain and solidity at conferences and local meetups. He is an architect, evangelist, speaker, and a known leader for  his contributions toward blockchain, data centers, Azure Bots, cognitive services, DevOps, Artificial Intelligence, and automation. He is the author of five books.

Rate this Article