Blockchain technology is gaining momentum and making its way into our daily news, drawing the attention of the worlds leading companies.
However, I see a lack of simple and easy to understand content for people to learn about smart contracts. That’s why I started writing simple articles for newcomers to the blockchain. Check my previous article where I introduce Blockchain and Smart Contract in a simple manner.
This article is a review on how to execute a smart contract, how does smart contract communicates with the outer world and the use case that is trending in the Ethereum network for the past few months.
Gas and miners motivation
The smart contract is a piece of code, which is executed on the computers in the network.
All computers (miners) executing the code must come to the same result and reach a consensus. In such way, we can be sure that the code was executed as it should be.
But the main question is what motivates the computers to execute a smart contract?
Ethereum blockchain came with a term Gas. Gas is a unit, which represents the amount paid for the code execution. Along with some smart contract function call, you have to declare the amount of gas and pay for it.
This motivates miners to run your code and earn money for that. Depending on the logic within the code, the gas price varies as well. You should treat Ethereum as a global server, where you pay for each transaction instead of monthly fee for some central server provider.
The gas as well motivates developers to write efficient code so that it would require less gas for the execution.
Communication with outer world
All the basic applications we use daily integrates with various external services (API’s). For example, a travel website, according to the weather outside, could propose different trips.
It means that this server has to connect to weather API to retrieve data and show information accordingly. So where is the catch here? The smart contract should also be able to do that, right?
The answer is no.
The main reason behind is that this code is executed on each and every node. It means that the call to weather API could happen at a different time as the nodes might start executing the
The main reason behind is that this code is executed on each and every node. It means that the call to weather API could happen at a different time as the nodes might start executing the code, not at the same time.
And in one second we could have sunny weather data returned, and in another, we can have a heavy rain. In such case, nodes would never be able to reach a consensus on the result of the smart contract.
Now you might think ‘..what the sh*t is Ethereum if you cannot use API’s as in normal application where various integrations are needed?..’
The solution — Oracle
Great news! There was a solution developed called Oracle. The idea is pretty simple. Instead of the smart contract calling external API, the API itself pushes the data to the blockchain.
The result is that all the nodes now have the same data within the network. It is implemented in a simple way, that contract triggers the event, external applications such as Oraclize listens to that event, retrieves data from the API and adds transaction with the result to the contract.
The solution seems legit. But on the other hand, you now deny the whole decentralisation idea and have to trust some central data provider.
Use case — crowdfunding
Ethereum creators provided some simple examples that could be built on their platform. I would like to cover one example to better understand possibilities the technology brings to the table.
I guess everybody knows Kickstarter. Project team sets minimum and maximum funding goals. They also have to trust Kickstarter that if the amount of money will be reached, Kickstarter will pay the team.
On the other hand, backers need to trust Kickstarter that they will return the money invested in if the goal is not reached or send money to the project team if the goal is reached. Such solution is very centralized.
This type of Fundraising got recently very popular for blockchain projects. Especially on Ethereum. Smart contract is written with identical rules.
People send money to the contract and they can be sure, that if the amount won’t be reached they will be able to claim back the money. All smart contract code is public and they can review it (of course you need to have some basic understanding of programming).
This approach removes the need of Kickstarter as an intermediary taking fee.
With the help of such crowdsale smart contracts, projects are raising Ethers (Ethereum blockchain currency) worth of millions USD.
Recently Bancor Crowdsale raised over $140 Million and all this amount of money was sent directly to a piece of code (smart contract) which processed transactions, assigned tokens in return and sent money to the team’s wallet. This is the real power of smart contracts!
Are you a developer? You can take a look at the piece of Bancor crowdsale code written in Solidity language. It should not be tough to read and understand the logic behind.
I believe that smart contracts have a huge possibilities to revolutionize the internet and this is just a beginning!
Enjoyed the article? Please let me know by clicking green CLAP below or send a recommendation to a friend. Thank you!