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!


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

    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
    January 15, 2019

    Solving Challenges with Smart Assets

    In late 2018, Waves Platform released Smart Assets on MainNet and launched Tokenomica, a fully compliant exchange for digital assets. This article, centered on use cases for Smart Assets, comes as the first in a series focused on how Waves solutions facilitate building the financial system of...

    From: WavesDEX
    January 14, 2019

    Waves to Take Part in Blockchain Gamer Connects

    Next week, Waves will participate in Blockchain Gamer Connects, the first event dedicated exclusively to blockchain games and held simultaneously with Pocketgamer Connects and PC Connects on January 21–22.Waves’ Inal Kardanov will make a presentation called “Fueling the Revolution,”...

    From: WavesDEX
    January 11, 2019

    Waves Christmas Game Proves a Success!

    Our Christmas game turned out to be a huge success. It entertained many over the holidays and the funds collected will benefit children from a hospice in Moscow.From 24 December to 8 January, hundreds of people had fun playing Waves’ Christmas game, developed in collaboration with Tradisys.In...

    From: WavesDEX
    January 10, 2019

    Waves Pushes Into UK With Wirex Integration

    The FCA-licensed digital money platform has recognised the potential of Waves to play a significant role in the future infrastructure of the internet.The future of blockchain is not simply cryptocurrency. It is blockchain and crypto, integrated into every sector and every area of life, just as...

    From: WavesDEX
    January 03, 2019

    Web3 Apps and Products: Trustless, Synergistic and Monetizable.

    We live in the era of tectonic shifts in society and technology. The shape of the future world is still quite vague, and changing all the time. Futuristic concepts that have been proposed not so long ago stop making sense or need to be adjusted. One thing is obvious — development of the...

    From: WavesDEX
    December 26, 2018

    Waves Launches Explorer 2.0

    The new version is optimised for mobile devices and fits perfectly within Waves’ unified design concept.With the Christmas holidays in full swing for much of the world, the Waves team is still working hard and is pleased to announce another important launch before the end of the year. The new...

    From: WavesDEX
    Upcoming ICO's
    This week overview
    Token Name Starts
    Cryptocurrency rates
    *Last hour average price&change
    Coin Name Price Hour
    Bitcoin logo BTC $3563.65848033 0.07%
    Ripple logo XRP $0.3171080467 0.04%
    Ethereum logo ETH $116.957698769 -0.15%
    Bitcoin Cash logo BCH $122.339514784 0.63%
    EOS logo EOS $2.3488357632 0.18%
    Tether logo USDT $1.0131672655 0.14%
    Stellar logo XLM $0.1029606043 0.18%
    Litecoin logo LTC $31.0387314331 0.15%
    Tronix logo TRX $0.0258098587 0.54%
    Cardano logo ADA $0.0424387944 -0.15%
    Binance Coin logo BNB $6.473119591 0.34%
    IOTA logo IOT $0.2969679188 0.38%