What are SMART CONTRACTS? [All you need to know]

Whether you are a developer or a non-tech person, this article is intended for you to get a brief overview of smart contracts, how they function on top of a blockchain and its general use cases.

What is a Smart Contract?

A Smart contract is a computer program (set of instructions given to a computer) that is deployed and stored on a blockchain.

What programming languages are used?

Like any other program, smart contracts are written in high-level programming languages like Solidity, Vyper or Rust in code editors or IDE’s like Remix, Foundry and Hardhat. But what makes them different is that they will only work on compatible blockchains. For example, Solidity is native to the Ethereum blockchain and works on Avalanche, Tron, Binance Smart chain and many more as well. For the Solana blockchain, Rust is the most notable programming language. We can use these languages to combine blockchains with smart contract logic to build useful applications.

When building an application, we usually have a frontend, backend and a database involved in the architecture. Let’s compare the Web2 and Web3 app architectures to understand the differences:

Comparison of Web2 and Web3 architecture

For the frontend, we tend to store the files on an Interplanetary File System (IPFS) as centralised servers can stop working at any time, which may cause our site to crash. This is important in the case of applications being built on blockchains because even if the backend is decentralised with smart contracts and the blockchain, the user would not be able to interact with the frontend if the centralised servers go down. That is why a distributed file system like IPFS is generally used to store the frontend files.

Benefits:

1.Promotes open source development

Since smart contracts are deployed to the blockchain, we are able to publicly view the source code they contain. This can help developers to use the code to build their own software.

2.Provides transparency

The open availability of the source code allows the public to ensure that there is no code infringement or behind-the-scenes decision making occurring. Recently, Twitter released important files to the public to ensure transparency. In these files, we were able to see how Twitter’s previous owners were lying to the public in the face and collaborating with politicians to take false actions such as banning user accounts for the wrong reasons. With the owner of Twitter, Elon Musk, planning to make their code public, normal users and programmers will be able to benefit from its transparency and open-source nature respectively.

Downsides:

1.Prone to hacks

You might be thinking that if the code is unchangeable and publicly available, what happens if there is a bug in any of the smart contracts? This might lead to our code being prone to hacks.

To tackle this problem, we can take a look at the following solutions:

  1. Upgradeable smart contracts

Upgradeable smart contracts are a way to stop the hack from continuing. This can be done through freezing the smart contracts or setting some kind of pause function in them to stop the hack. For example, let’s say a hacker found a loophole in the programs and decides to deplete all the money from it (Fun fact: Smart contracts are able to store cryptocurrencies in them). When this happens, the team working on the smart contracts can call the pause or stop functions that they had previously built in to prevent the hack from continuing.

2. Self-Destruct

The Ethereum blockchain (or more specifically the Ethereum Virtual Machine — that executes our smart contract logic) provides an opcode called SELF-DESTRUCT that can stop further interaction with the contracts and delete them from the blockchain. It is important to note that the history of the smart contracts still remains on the blockchain. Although this is not a favourable method used by most teams, it is still available for use.

Conclusion

Although this is a very basic concept in blockchain development, understanding smart contracts is a very vital step to get started with building applications. The programmability of a blockchain like Ethereum combined with the power of smart contracts can help us to build potential decentralised applications that can solve a lot of issues we face today with centralised applications.

I hope you enjoyed reading this article and found it to be helpful. Please follow, share and subscribe to get updates on more interesting and insightful articles in the future :)

Subscribe to McGrath Coutinho
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.