A Beginner’s Guide to Understanding the aelf WhitePaper (Part 2)

What is a smart contract?

ælf
aelf
4 min readAug 13, 2020

--

If you have read the whitepaper of some blockchain projects, you might find them difficult to understand or even make no sense. As a result, readers (not speculators) are often at a loss as to what these projects are trying to do. Unfortunately, many projects often assume their readers are all experts and can understand the whitepapers with no difficulty. In reality, most blockchain projects are much more complex than Bitcoin. Therefore, if readers only know how Bitcoin works, they still cannot understand these projects’ whitepapers. If you want to draw potential developers to your platform, it is necessary to provide a beginner’s guide to understanding your whitepaper.

Yesterday we talked about what is the blockchain, today we would like to introduce the smart contract.

What is a smart contract?

The definition of smart contract in many books, articles and videos is very misleading from a developer’s point of view. They often explain that smart contract is a new generation of legal contract, deed, or proof of ownership, etc., and since they is code-based, smart contracts are highly intelligent. But this definition is only for those working in finance or other sectors who do not know computer science and coding. They need only to know that smart contract is very powerful, and that’s enough (in some sense, this is all very well). But what is smart contract exactly?

In fact, smart contract is neither smart nor is it a contract, it is just a string of code. So why do people call it smart contract rather than a more intuitive name? That’s because it has been called smart contract all along, and programmers are too lazy to change the name. Smart contracts, like Python or Java codes, are written in a high-level language, and compiled into bytecode to be run as opcode on a virtual machine. You might already know things like JVM and Python-VM, or EVM on the Ethereum blockchain. For the aelf project, smart contracts are written in C#, and they are run on the .NET framework after being compiled.

Calling the execution of a smart contract is in some sense similar to making an http request: In a traditional requesting process, you type in a URL to tell the remote server to send you back some data (html, css, javascripts, etc.), or tell the server to execute some server-side programs which could be written in Java to change some states of the server. The same is true for smart contracts. Just like a request, we send a transaction to the target contract address, whether it costs cryptocurrency or not. When the contract receives the calling request from the transaction, it will execute some specific functions in the smart contract code, depending on the parameters in your transaction. If there is enough gas, the executing result will change this smart contract’s state, send you the data of the result, or send you cryptocurrency.

However, in comparison to the instant response from a remote server after an http request, the execution of a smart contract will take some time after you send a transaction. As I have mentioned in the Bingo game article, when you send a transaction, the transaction will be broadcast to as many nodes as possible, and every mining node will include it into its candidate block. After a while, when one mining node produces a new block, it will broadcast this block to other nodes, of course, this block is confirmed. This process will take some time, and for most real applications only producing one new block cannot guarantee the safety and validity of the transaction, so more blocks should be concatenated consecutively after this block. On the aelf blockchain, at least 8 new blocks should be generated after the production of the block containing the transaction. Of course, if one block containing this transaction is finally packaged by a mining node, when satisfying a certain consensus condition, the target smart contract is then executed on a full node (full node can be a mining node, or vice versa). But with more and more blocks being generated after this block, it will be virtually impossible to tamper with the execution result of this smart contract by forking to another chain.

In the Bingo game example, the “bet” button is such a method in our smart contract. When we place a bet, a transaction is sent to the contract. After one block is packaged, the method is executed and thus the contract will know how much you want to bet. In order to let the contract know your bet amount and to avoid anyone tampering with your bet amount, you have to wait until 8 subsequent new blocks are produced. So how long does it take? As is shown in the last article or in the demo video, it takes about 30 seconds. In fact, no one knows exactly how long does it take to generate 8 blocks, but we know that after 30s more than 8 blocks must have been already produced.

Having explained these two basic concepts, it is much easier to understand any blockchain projects, including aelf. No matter how sophisticated the technologies a blockchain project applies, they will all be based on these two concepts.

In the next article, we will dive into the aelf blockchain whitepaper to demystify all the important features of this enterprise-level project! To be continued.

— Join the Community:

· Get on our Telegram Discord Slack and Kakao channel

· Follow us on Twitter Reddit and Facebook

· Read weekly articles on the aelf blog

· Catch up with the develop progress on Github

· Telegram community in 한국, 日本 語, русский, العربية, Deutsch, Italiano and Tiếng Việt

· Instagram: aelfblockchain

· YouTube Channel: aelf

For more information, visit aelf.io

--

--

ælf
aelf

ælf, the next breakthrough in Blockchain.