DEV Community

Cover image for Understanding Smart Contracts
Godspower Eze
Godspower Eze

Posted on

Understanding Smart Contracts

Smart contracts are by far one of the most pivotal innovations introduced in the blockchain ecosystem. It opened a new world of possibilities. But, what exactly are smart contracts?

This article would focus on explaining in the most basic sense what smart contracts are.

What are Smart Contracts?

Smart contracts are programs that run on the blockchain. Or, deployed onto a blockchain.

Every smart contract has a unique address called a contract address which is generated on deployment.

Background Story

Blockchain technology was popularized by Satoshi Nakamoto with the creation of Bitcoin, the first decentralized digital currency.

On the Bitcoin Software (also known as Bitcoin Core), a programming language called Bitcoin Scripting Language(or Bitcoin Script) is used for interaction. It is used to define how coins are moved in the network.

Note that the Bitcoin Blockchain wasn't built with the Bitcoin Script rather the Bitcoin Script is built on top of it. The first implementation of the Bitcoin blockchain was built with C++ and other implementations have been built since then.

Based on the explanation above, the Bitcoin script is a smart contract because it runs on the blockchain and it defines the rules of how bitcoins are handled. But, this has a limitation. It is turing incomplete. It's rigid and can't be used for most use cases other than Bitcoin. It was built for Bitcoin and it alone it.

Developers needed a way to build on the Blockchain without having logical limitations. This is where Ethereum comes in.

In late 2013, Vitalik Buterin in a blog post titled Ethereum: The Ultimate Smart Contract and Decentralized Application Platform described an idea for a Turing-complete blockchain – a decentralized computer that, given enough time and resources, could run any application.

Ethereum launched in 2015 allowing developers to build smart contracts with turing-complete programming called Solidity. Since then other smart contract compatible blockchains and more languages for building them have come into the space.

Although Bitcoin Script can be seen as a smart contract, the terms smart contracts weren't used that much before Ethereum. Therefore, Ethereum popularized the idea of smart contracts while building an ideal version.

How do Smart Contracts Work?

They work like most computer programs would typically work. A set of instructions are defined and using those instructions you could perform certain operations if the necessary conditions are met.

One distinct factor is the smart contract depends on the blockchain for storage. And most interactions are done within the confines of the blockchain. They can't easily interact with the other side world like calling a WEB API.

Smart contracts are compiled to bytecode and then run by the Ethereum Virtual Machine (EVM).

The EVM can be seen as a processor containing Operation codes (also called OPCODES). Every section of the bytecode has its representation in the Operation code which simply tells the EVM what to do with them.

Are Smart Contracts smart?

The term word smart in the smart contract gives off the idea of something related to artificial intelligence. But, there is nothing smart about smart contracts. Until we start calling computer programs that use "if/then" statements "smart", smart contracts are not smart.

Are Smart Contracts actual Legal Contracts?

No, they are not.

Smart contracts follow the fundamental idea of a legal contract which is adhering to predefined set rules. But, smart contracts are just like most computer programs and best define how they work.

Attributes of a Smart Contract

  • Immutability

Once smart contracts are deployed to the blockchain they cannot be changed. It is impossible to do that.

This is a blessing and a curse because, before smart contracts, developers weren't used to building programs that cannot be changed but at the same time, this helps us ensure security during development and after deployment.

During development, smart contract developers build with the mindset that the smart contract is unchangeable so they consider a lot (especially security). After deployment, as developers, we are sure that our contract cannot be changed.

  • Publicly Available

All smart contracts are public. They are publicly available if a smart contract is deployed onto a public blockchain (which is mostly the case).

Every public blockchain has an explorer where most activities performed on the blockchain are displayed. To find a smart contract, all you need to do is get the contract address and search it on explorer.

This also means that anyone can interact with a deployed smart contract. Anyone.

  • Transparency

Every transaction with the smart contract from the most basic to the most complex can be viewed on the explorer.

Transactions are operations that alter the state of a smart contract. Read operations are not transactions.

This helps for proper auditing.

Applications of Smart Contracts

Smart contracts have been used in many ways but two of the most profound use-cases are Fungible tokens (ERC20 Tokens) and Non-fungible tokens(ERC721 Tokens) popularly known as NFTs. Let's see how they work briefly.

  • ERC20 Tokens

Smart contracts serve as a tool for building programmable money (also digital money) and ERC20 is a standard that allows for easy integration of this money across platforms. The standard simply ensures that tokens must have a set of programming elements (functions, methods and events) to be interpreted accordingly.

ERC20 Tokens are tokens that follow this standard. They are fungible (replaceable by one another) like native digital currencies (like ether and bitcoin) but are built using smart contracts.

  • ERC721 Tokens

ERC721 is a standard just like ERC20 but this specifies a way of building a token that is not fungible. Fundamentally, It builds on the idea of digital rarity and uniqueness.

In the past months, we have seen NFTs make mad moves with some selling for millions of dollars.

Conclusion

Ethereum is the blockchain of context here, but the ideas discussed can be transferred to other blockchains.

Smart contracts made possible the most groundbreaking innovations in the blockchain space. One of which is Defi (Decentralized Finance). Most Defi applications like Uniswap, Compound or MakerDAO would be not in existence without smart contracts.

Just like most innovations, it has had its fair share of challenges which are primarily security-related. For example, when a Decentralized Autonomous Organization (DAO) called "The DAO" got hacked in 2016, millions of ether (ETH) were stolen due to flaws in their code. Most of these hacks occurred as a result of human error during development.

Security is a very important aspect of smart contracts and it can't be overemphasised.

Building smart contracts is a skill that is valuable and becomes increasingly valuable as the space evolves. Check out this tutorial that teaches how to build your first smart contract using solidity.

Feel free to drop a comment if you have questions and also share if you found this helpful. Bye for now.

This post was originally published here on Blockchaintotheworld.com

Top comments (1)

Collapse
 
roberttony03 profile image
Robert Tony

Great overview of smart contracts! It’s fascinating to see how they are reshaping industries. For anyone looking to dive deeper, collaborating with a smart contract development company can provide the expertise needed to navigate this innovative landscape effectively. Thanks for sharing!