If you have been hearing about smart contracts and probably wondering what it really means, be assured that by the end of this post, you are going to understand in great detail what smart contracts are, its pros, some limitations, use cases and hopefully a little about the process of creation.
I would also like to thank Alejandro for the question asked on the Understanding the absolute basics about blockchain which this post is an answer to.
So in the Ethereum blockchain, there are two different types of an account that can be created, first, an externally owned account long for (EOA) and a contract account.
EOAs are essentially those type of accounts you and I can create and control through metamask wallet which is external to the Ethereum platform or protocol, these accounts are created without cost and controlled by anyone with the private keys cryptographically signed.
Contract account are not controlled by users unlike EOA, they are instead controlled by a program code commonly known as smart contracts that is executed by the Ethereum Virtual Machine (EVM). its creation has a cost and they do not have private keys hence are said to ‘self-controlled’ based on the logic of its program code. its worthy to note that, contracts only run if they are called by a transaction, Contracts never run “on their own”.
Similarly, both types of accounts have Ethereum address and can send and receive ether, but how they process these transaction is what differs, when a transaction destination is a contract address, it causes that contract to run in the EVM, triggering the codes to perform actions that were defined in it, such as sending, receiving etc.
what then is a smart contract?.
A little history - The term “smart contracts,” was coined by Nick Szabo in the 1990’s, he was trying to figure out a way to incorporate legal principles into the digital space, such that a breach of contract is prohibited or made very expensive. He also went on to define it as “a set of promises, specified in digital form, including protocols within which the parties perform on the other promises.”
Vitalik Buterin gave his own definition as: “a mechanism involving digital assets and two or more parties, where some or all of the parties put assets in and assets are automatically redistributed among those parties according to a formula based on certain data that is not known at the time the contract is initiated.
In a simple sense as regards the (ethereum) blockchain, **Smart contracts are simply self-executing immutable (once deployed, unchangeable) programs that is stored and runs on an Ethereum blockchain when predetermined conditions are met. The codes, conditions and functions it contains exist across a distributed, decentralized Ethereum blockchain network.
The basic idea of how a smart contract works is as follows
1.Logic is encoded into a smart contract program.
2.Nodes on the EVM compile, validate, store, and replicate the smart contract across the network 223
3.When the predetermined condition(s) occur, the contract is executed by the nodes on the network
4.Changes are made to the appropriate accounts on the network as a result of successfully executing the contract.
These are some of the benefits and properties of smart contract.
Security – smart contracts are encrypted and have a high degree of security
Accuracy – contracts are validated by many nodes on the network Autonomous – there is no need for a third party to be involved in the execution of a contract, lessening the potential for bias or mistakes
Automation- smart contracts are a tool for automating business logic, and allowing seamless transaction without intervention.
Speed and efficiency – with the elimination of third parties, meaningless and time consuming manual processes of enforcing a condition, smart contracts ensures an efficient and fast execution.
Transparency – on a theblockchain, all parties have access to the shared ledger; transactions can be audited and tracked.
Permissionless - anyone anywhere in the world can write smart contracts and deploy it to the ethereum network, provided you have required eth to deploy and you (or you can meet someone else) can code the smart contract.
Nevertheless, there are also drawbacks to be aware of. Since the codes are written by people, they can make mistakes and this makes the contracts vulnerable to attacks, and leading to detrimental asset loss. A good example of this is the DAO, where developers’ mistakes in the code were costly for the users and the company, Hackers exploited the errors and stole about $60 million.
Furthermore, a smart contract cannot exceed 24kb or else it will run out of gas.
Having understood the basics of smart contracts, it would not come as a shock that a programming knowledge would be needed to create a smart contract, there are multiple high-level programming languages for programming smart contracts. Such llc, viper, serpent, bamboo, solidity. However, Some of these languages are deprecated and others are yet to gain a certain level of acceptance. Solidity is by far the most popular, and hence de facto high level language of Ethereum and programming smart contracts, it was created by Dr.Gavin Wood.
Solidity code needs a compiler to take its code and convert it into bytecode that is understandable by EVM.
In addition, other tools like remix ide and metamask are other important tool of development.
In conclusion, as blockchain continue to evolve, smart contracts have enormous potentials to further disrupt the health, finances and banking, real estate industries, the possibilities are endless.