What is a Smart Contract? A beginner’s guide to Blockchain
Afterwards, non-highest bidders will call the withdraw() function defined by lines 44~55. There is no separate time check, so as long as the contract is valid, withdrawals can be made anytime.
Have you noticed this line in each function? This is called an event; its purpose is to leave a log of each function and that it was properly executed. It returns a receipt as a result of a transaction, which contains the said event. If the transaction had failed, there would be no event recorded.
If you’d like to look at an upgraded version of this smart contract, you may look at https://solidity.readthedocs.io/en/latest/solidity-by-example.html#id2. 😉
Before we look at why we need these smart contracts, we’ll briefly summarize the characteristics of smart contracts. From a technological perspective, smart contracts have the following features.
1) Anyone can distribute the contracts.
2) Anyone can verify the contracts — not just the owner.
3) Execution of the code can be automatized.
4) It is difficult to forge/alter.
This means smart contracts are most appropriate for situations where transparency is an issue, where intermediaries have previously been necessary, and where transaction costs are incurred. Using Etherscan or Decentralized Metadata and Source Code Repository, anyone can look at all contracts that have been distributed.
Additionally, smart contracts are effective tools in setting up trustless networks on the blockchain. If Alice needs to send $50 on the last day of every month, this contract is executable without going through banks or other certified third parties.
The advent of Ethereum has resulted in smart contracts being used in a variety of manners.
- Initial Coin Offering (ICO)
An exemplary case is ICO, where smart contracts were used to create tokens and perform their Initial Coin Offerings. Most of these tokens follow an ERC-20 protocol, which was suggested from the EIP(Ethereum Improvement Proposal) 20, and defines the standards for a token-type smart contract. This EIP defines ERC-20 tokens’ standards (for qualities such as token transfers, exchanges, and authorizations) they must follow. On a side note, ERC stands for Ethereum Request for Comment.
*EIP(Ethereum Improvement Proposal) Ethereum is a decentralized network, meaning anyone can contribute with new ideas for improving the Ethereum network through EIP.
The reason token sales were conducted using smart contracts is that the information contained by the smart contracts is displayed on the blockchain network with complete transparency, ensuring its credibility. Airbloc’s director Won-Kyung Ryu, having conducted an actual token sales, commented as below in our interview:
“I think using smart contracts greatly enhances the credibility of token sales to participants because we can display the progress of the sale, the number of tokens issued and sold — all in a transparent manner.”
If we can implement game items with smart contracts and prove ownership of users, item transactions become as easy as cryptocurrency transactions. This eliminates the need for a separate trading platform, and items can be traded directly within the trading system at desired prices. In this case, each smart contract must be mapped to a specific item, and it becomes important that the contract be discrete and not divisible(as is the case where 1 ETH can be divided into 0.5ETH, etc.). Standards that take this need into account are ERC-721 and ERC-1155. For items designed with this protocol, the ownership lies with the individual instead of the developer, and can be traded with or without the developer’s approval. Also, this characteristic would be useful in proving ownership of a financial product by utilizing these NFTs(Non-Fungible Tokens).
In addition to fundraising and game items, smart contracts are being used in various sectors such as decentralized finance(De-fi), wallets, decentralized exchange institutions, etc.
Even so, smart contracts do not perfectly solve the limits of conventional contracts.
Smart contracts cannot retrieve information outside the blockchain by themselves. In other words, we might encounter problems when certain information is necessary during the process of verifying whether smart contract conditions are met. For example, let’s say we have a contract that says ‘If the price of ETH rises above $1,000, A provides B with 1 ETH.’ Here, the smart contract only functions if information on whether the price of Ethereum is over $1,000 or not. Therefore, the contract is only executable when the cryptocurrency exchange’s accurate Ethereum price data is retrieved, which lies outside the blockchain.
Here’s the catch — during the retrieval process, the wrong data may be retrieved, or the data may be intentionally altered. In other words, specific information about a specific condition needs to be retrieved, and if this information is dependent on a third party, this inevitably leads to a credibility issue. To resolve this inherent issue, many startups are striving to provide accurate information necessary for generating and executing smart contracts.
Another inherent limitation of smart contracts is that they are not editable once they have been distributed. On one hand, it is this rigidity that imbues smart contracts their credibility, but on the other, this can become a potential weakness that can be exploited. There have been cases where smart contracts have been hacked or become permanently dysfunctional because of this characteristic, the most prominent case being SmartMesh. The smart contract distributed by the SmartMesh team contained a security flaw, and the hacker used it to issue/sell additional tokens. Also, there was a case where the security flaw resulted in 513.774.16ETH contained in wallets became permanently non-withdrawable.
Smart contracts deal directly in digital assets, and therefore safety is paramount when developing smart contracts. In the blockchain industry, it is becoming standard procedure to conduct a security audit before distribution. We will look at how security audits are performed in further detail in future articles.
This article was to look at smart contracts as an effective method to solve many of the inherent limitations of the conventional contracting system, and that they are being used in various fields. We’ve also noted that smart contracts are not able to solve every problem with the contract system.
What’s interesting about smart contracts is that it is continuously improving as the developing environments centered around the blockchain developers’ community also improves. We hope this article serves those who have been interested in blockchain and smart contracts, and any questions and/or feedback is always welcome at audit@haechi.io.
Thank you for reading. 🙆🏻♂️
Published at Mon, 06 Jan 2020 07:31:25 +0000
{flickr|100|campaign}
