Cover photo

Blockchain 101 #13: Smart Contracts and Solidity: Propelling the Evolution of Blockchain Technology

Explaining Smart Contracts, Solidity as the programming language on EVM Blockchains, and Smart Contract Toolkits (Foundry vs Hardhat)

The dawn of blockchain technology has birthed a paradigm shift in how transactions and agreements are executed, with smart contracts emerging as the keystone of this transformative era. At the heart of this revolutionary wave lies a pivotal element: Solidity, the programming language that fuels the execution of Ethereum smart contracts.

Understanding the Essence of Smart Contracts

Smart contracts, encapsulated within the immutable blocks of a blockchain, have redefined trust and automation. These self-executing contracts, encoded in computer programs, dictate the terms of an agreement, automatically executing actions when predetermined conditions are met. The resultant decentralisation obviates the need for intermediaries, fostering transparency, efficiency, and security across diverse sectors such as finance, supply chain, and beyond.

Solidity - The Art and Science of Smart Contracts

Solidity, designed by Ethereum's Vitalik Buterin, is a programming language tailored for creating smart contracts on the Ethereum blockchain. With a syntax resembling JavaScript, it appeals to web developers, offering a statically typed system for enhanced code reliability. Following object-oriented programming principles, Solidity supports modular and reusable code. Developers need to be mindful of gas costs, a crucial factor in optimising contract efficiency and managing transaction fees. Security is paramount, and Solidity provides built-in features and best practices to prevent vulnerabilities. Its tight integration with the Ethereum ecosystem facilitates seamless interaction with other contracts and decentralised applications. Supported by tools like Remix, Solidity is actively developed, ensuring regular updates for improved security, functionality, and usability.

Here is a sample "Hello World" code from Solidity by Example -

// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.20 and less than 0.9.0
pragma solidity ^0.8.20;

contract HelloWorld {
    string public greet = "Hello World!";

What are Ethereum Virtual Machines (EVMs)?

Ethereum Virtual Machines (EVMs) are integral components of the Ethereum blockchain network, playing a crucial role in the execution of smart contracts. The EVM is a runtime environment that enables the processing of smart contracts written in Solidity. It provides a standardised platform for the deployment and execution of smart contracts across the Ethereum blockchain network.

The EVM operates as a virtual machine, meaning it is a software-based emulation of a physical computer. It runs on each node of the Ethereum network, ensuring consistency and uniformity in the execution of smart contracts regardless of the node's underlying hardware or operating system.

When a smart contract is created in Solidity, it is compiled into bytecode, a low-level representation of the contract's instructions. This bytecode is then executed by the Ethereum Virtual Machine. The EVM processes and validates transactions, updating the state of the Ethereum blockchain according to the terms and conditions specified in the smart contract.

One of the key features of the EVM is its ability to provide a secure and deterministic environment for smart contract execution. Deterministic execution ensures that the outcome of a smart contract is the same across all nodes on the network, promoting consensus and trust among participants.

So when a Blockchain is said to be EVM-compatible, it means that the Blockchain is built on top of the Ethereum Layer 1 Blockchain (check out Gideon's article to understand Blockchain Layers).

Some examples of EVM-compatible blockchains are Polygon, BNB Smart Chain and Avalanche

EVM Blockchains and Solidity's Symphony

The Ethereum Virtual Machine (EVM) serves as the crucible where Solidity's code metamorphoses into bytecode, ensuring decentralised and deterministic execution of smart contracts across the Ethereum network. This intricate dance between Solidity and the EVM not only solidifies Ethereum's position in the blockchain sphere but also underlines the compatibility and symbiosis crucial for the proliferation of decentralised applications.

Smart Contract Toolkits - Foundry vs Hardhat

In the dynamic landscape of smart contract development, Foundry and Hardhat emerge as contenders, each offering a distinct approach to simplifying and enhancing the development lifecycle.

Foundry, a newcomer on the stage, pivots on simplicity and user-friendliness. Tailored tools for deployment, management, and interaction with smart contracts are Foundry's forte, allowing developers to focus their energies on the logic of their applications rather than grappling with the complexities of deployment.

Hardhat, in contrast, positions itself as a comprehensive and extensible development environment. Armed with an arsenal of plugins, built-in tasks, and unwavering support for the latest Ethereum features, Hardhat beckons developers seeking a robust framework to construct intricate decentralised applications.

Despite both Hardhat and Foundry utilising Solidity for smart contract development, it is important to know that they differ in their compile time, testing languages, and dependencies they offer. Let's explore some of the distinctions:

Difference #1: Compile Time

Foundry outperforms Hardhat in compile-time efficiency. A comparative analysis involving the LSP-smart contracts on Lukso (an EVM-compatible Blockchain) reveals a notable contrast. The identical contracts took approximately 39.33 seconds to compile with Hardhat, whereas Foundry accomplished the task in approximately 26.22 seconds.

Difference #2: Testing Language

In Hardhat, tests predominantly utilise Javascript or Typescript, while Foundry opts for Solidity. Some developers find it inconvenient to master additional languages such as Javascript or Typescript solely for testing Solidity contracts.

By exclusively using Solidity for testing in Foundry, developers experience less context switching between languages. Foundry's streamlined approach aids in maintaining focus and deepening proficiency in Solidity. Additionally, executing tests in Solidity proves to be considerably faster than in Javascript as well.

Difference #3: Dependencies

Hardhat relies on the Node Package Manager (npm) (aligning with the broader JavaScript ecosystem) as its primary tool for managing dependencies. In contrast, Foundry adopts a default approach of managing dependencies through the integration of git submodules. This nuanced difference extends beyond mere technical variance, influencing the manner in which external libraries and modules are incorporated into the development ecosystem.

The trajectory of blockchain technology hinges on the relentless evolution of smart contracts, Solidity's prowess, and the adept utilisation of development frameworks. As Solidity continues to be the language of choice for Ethereum, Foundry and Hardhat serve as catalysts, propelling the metamorphosis of concepts into reality.

In this intricate dance of technology, the synergy between smart contracts, Solidity, and development frameworks is not just shaping the future of blockchain but forging an epoch where decentralised, trustless architectures are not merely a possibility but an inevitability. The canvas is vast, the brushes are innovation and collaboration, and as we paint the future of blockchain, the strokes of smart contracts and Solidity resonate as the defining elements of a decentralised masterpiece.

We, from Blockchain at NTU, thank you for being part of this enlightening journey and extend a warm welcome to the enthralling universe of blockchain!

NOTE: Articles written by Blockchain at NTU ARE NOT FINANCIAL ADVICE!

Written By:
Dann Wee
Research Director of Blockchain at NTU Club AY23/24

Social Media Links:
| Facebook | Instagram | Twitter | Linkedin | Discord |
| Telegram Group | Telegram Channel |

Collect this post to permanently own it.
Blockchain at NTU logo
Subscribe to Blockchain at NTU and never miss a post.
  • Loading comments...