Inal Kardanov: The Hitchhiker’s Guide to Waves Smart Contracts. Part 1

wavesplatform waves smart-contracts programming blockchain

On September 10 Waves Platform released a new version of node, which has the support of Smart Contracts in their first implementation. In this article, we’re going to focus on the idea of Waves Smart Accounts and what makes it different than other existing solutions. We will begin with a brief introduction with some definitions of smart contracts then we’re going to see the difference between Bitcoin script, Ethereum Smart Contract and Waves Smart Accounts. After that, we will provide some use-cases implementation using our solution and explain more about our RIDE language.

So let’s prepare a cup of coffee and begin our journey!

Intro

Blockchain word has been around for a while and every day we’re hearing this word more and more. Usually, in the second or third sentence about the blockchain we hear about smart contracts, so they’re tightly coupled.

The definition of a Smart Contract

Most of us already heard about smart contracts and the first thing that comes to our mind when we say a smart contract is Ethereum, it is a little unfair, because the first proof-of-concept of a smart contract is Bitcoin Script. Actually, there are many different blockchain platforms which implemented the idea of a smart contract and the definition of the smart contract was introduced 20 years ago by Nick Szabo.

We can define a smart contract as follows:

  • A smart contract is a program that runs on the blockchain and has its correct execution driven by the consensus protocol. A contract can encode any set of rules represented in its programming language. Therefore, smart contracts can implement a wide range of applications, including financial instruments and autonomous governance applications.
  • The idea of a smart contract as defined by Nick Szabo is to satisfy common contractual conditions, to minimize exceptions both malicious and accidental, and minimize the need for trusted intermediaries.

Bitcoin Script

Now let’s understand the concept of Bitcoin script — the language which is used for creating scripts in Bitcoin Network. Basically, the script is a Forth-like bytecode stack-based language but what makes bitcoin script different that is designed purposely so the script execution is guaranteed to terminate. Some characteristics that are available in Forth but are not available in Script include variables, arrays, functions, and loops. Bitcoin Script does not provide any primitives that allow random write access to either of the stacks. A very important thing to understand — there are no accounts in the Bitcoin network, there are only inputs and outputs. Every transaction is a list of outputs, which refers to inputs. Bitcoin Script can be attached to any input and it defines the rule of converting an input to an output (sending bitcoins to person, for example).

Bitcoin Script key features:

  • Script language includes the necessary cryptographic operations and primitives, has many different opcodes (many of them are disabled), but there are no loops. Script memory access is stack-based.
  • A script always terminates. The execution time is bounded above by the length of the script after the instruction pointer and this limitation prevents denial of service attacks on the nodes which are validating the blocks.

Why do we need smart contracts

Since the first day of development, we had in our mind the main goal which is to cover two types of tasks for smart contracts:

  • Simple and well-defined tasks like multisignature and atomic swap.
  • Dapps with custom logic and almost limitless possibilities.
  • There is another common use case for smart contracts — tokens. For example, in Ethereum Network the vast majority of working contracts are ERC20 standard tokens. But in our case, it is not relevant, because we have lightweight tokens in the core (more details here). It is not necessary to create a contract to issue a token, you just have to send one transaction of the predefined type.

    With our first implementation of smart contracts, we decided to cover first types of tasks, i.e. multisignatures, atomic swaps, escrows. This will provide functionality for implementing the most-needed scenarios as well as more elaborate protections for coins and with our data transaction, there will be a way to post Oracle data to the blockchain.

    In the early stages of development we have created a list of requirements for such smart contracts:

  • Maximum security. Smart contracts for simple tasks should be simple, secure and easy to start. Every month we see news like this, we want to avoid stupid bugs for simple tasks. Smart contracts language should help to avoid bugs.
  • No need for gas. To do this, the script must be executed for a predictable amount of time.
  • About Waves Blockchain

    Before moving on to the technical details of the implementation, let’s talk a little bit about Waves blockchain, it will be important for further understanding.

  • There are currently 12 different types of transactions in the Waves Blockchain.
  • There are no inputs and outputs (as in Bitcoin), but accounts. Every transaction is performed by one account.
  • By default, the correctness of the transaction is determined by the current blockchain state and the validity of the signature. JSON representation of the transaction is quite simple:
  • JSON of transfer transaction in Waves Network

    What is Smart Account?

    The latest release of Waves Node makes Smart Accounts enabled. I will try to give you an intuition what is a smart account.

    Basically, the smart account is an account with attached transactions checking script. in other words, a script which is attached to an account so the account can validate every transaction before confirming it.

    Facts about Waves Smart Accounts (NO GAS is the best fact)

  • The Waves smart account can check if the transaction meets certain conditions which are defined in a script before the transaction is submitted to be included in the next generated block.
  • It will enable users to use a script on their accounts that will allow them to control all outgoing transactions so they can get the benefits of such smart accounts in different situations including 2FA, Multisig, escrow and oracles among others.
  • It can be used to set different rules on the checking process of transaction validity. For example, the user can set a rule that transactions from an address can be sent only if the block height is greater than N or the user can set a rule that all transactions from the address are valid (even without signature validation).
  • Smart accounts are predicated based on: the transaction type and fields, the Height or timestamp and finally the Data on the blockchain (Data transactions and Oracles).
  • In next part I will discuss about RIDE smart contracts language, it’s idea and technical details about costs, standard library and we will write our first smart contract for Waves using IDE.

    Stay tuned!

    P.S. You can find a lot of details and explanations, including Smart Accounts White Paper on Waves website.

    The Hitchhiker’s Guide to Waves Smart Contracts. Part 1 was originally published in Waves Platform on Medium, where people are continuing the conversation by highlighting and responding to this story.

    Original article was created by: Inal Kardanov at blog.wavesplatform.com

    Disclaimer: This article should not be taken as, and is not intended to provide, investment advice. Please conduct your own thorough research before investing in any cryptocurrency or ICO.

    Interested in Cryptocurrencies and ICO's?

    Follow our telegram channel for daily cryptomarket reports!

    Join @cointrends

    Stay on top of Altcoins and ICO trends.

    Subscribe to our free Weekly Cryptomarket report

    Delivered once a week, strongly to your inbox.

    Subscribe to our mailing list
    September 20, 2018

    Waves Reaches 1 Million Wallets!

    We have hit a major milestone in the history of Waves: our one millionth account has been created!Waves was launched in June 2016 with the intention of becoming a mass-market blockchain platform. Two and a half years later, we celebrate reaching a very impressive one million wallets created!We...

    From: Waves Platform

    WAVES Listed On Bithumb

    We are excited to announce a new exchange listing! Bithumb, the largest South Korean cryptocurrency exchange, will list WAVES token for trading.Bithumb, which has its headquarters in Seoul, has just announced a new schedule of coin listings. The exchange recently published a Cryptocurrency...

    From: Waves Platform
    September 18, 2018

    The Hitchhiker’s Guide to Waves Smart Contracts. Part 2

    On September 10 Waves Platform released a new version of node, which has the support of Smart Contracts in their first implementation. In the first part we focused on the idea of Waves Smart Accounts and what makes it different than other existing solutions. In this part we will focus more on...

    From: Inal Kardanov
    September 14, 2018
    September 12, 2018

    Waves Promotes Crypto Ecosystem On ‘Blockchain Island’.

    We are very excited to announce that our CEO Sasha Ivanov has started negotiations with the Maltese government, concerning Waves’ accreditation to work within the territory of the state.Waves CEO, Sasha Ivanov, met with Hon. Dr Joseph Muscat, Prime Minister of Malta, and representatives of...

    From: Waves Platform
    September 10, 2018

    Waves Platform Enhances Blockchain Functionality

    It’s finally happened! We have released a system update that will start the process of activating Smart Contracts on the Waves MainNet.We have released a new system protocol for the Waves blockchain that will enable Smart Contracts. The update initialises a process of voting for miners on the...

    From: Waves Platform
    Upcoming ICO's
    This week overview
    Token Name Starts
    RoBust Defense Token (RBDT) logo RoBust Defense Token (RBDT) 1 days
    Yumerium (YUM) logo Yumerium (YUM) 2 days
    Blockchain.io (BCIO) logo Blockchain.io (BCIO) 3 days
    Cryptocurrency rates
    *Last hour average price&change
    Coin Name Price Hour
    Bitcoin logo BTC $6696.48511045 -0.02%
    Ethereum logo ETH $243.218681328 -0.17%
    Ripple logo XRP $0.5665174557 -0.26%
    Bitcoin Cash logo BCH $486.603565181 -0.31%
    EOS logo EOS $5.9413402198 -0.31%
    Stellar logo XLM $0.2776872447 -0.83%
    Litecoin logo LTC $60.7507933117 -0.16%
    Tether logo USDT $1.0006295521 0.11%
    Cardano logo ADA $0.0896386823 -0.18%
    Monero logo XMR $121.116194191 -0.79%
    DigitalCash logo DASH $204.351974192 -0.36%
    IOTA logo IOT $0.6070285748 -0.18%