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
    October 09, 2018

    Waves Monthly: September Review

    This month has been a very active one for development. We have made many improvements to our platform and made one especially big step forward in Waves’ development!With the release of some long-awaited features, Waves matures from a custom tokens network to something more robust, versatile...

    From: Waves Platform
    October 03, 2018

    Stateful Smart Accounts, part 2: Implementing ERC-20 and NFT(ERC-721) step by step

    Stateful Smart Accounts, part 2: Prototyping ERC-20 and NFT(ERC-721) step-by-stepRecently we discussed how Waves Smart Accounts enable stateful contracts with the simple example of incrementing a number.Waves already implements tokens at its core, but today let’s ignore that — just for...

    From: Ilya Smagin
    October 02, 2018

    Become a Waves Tech Ambassador!

    We are opening a new ambassadors initiative, but this time it’s for techies. Ladies and gentlemen, we are excited to introduce the Waves Tech Ambassadors Program!As you may know, we have been running a huge brand Ambassadors Program worldwide, and it’s already bearing fruit — Waves...

    From: Waves Platform
    September 26, 2018

    Smart Accounts Finally Activated On Waves MainNet!

    It’s happened! After miners voted overwhelmingly to approve the feature, we now have the first phase of smart contracts available to users.We are very pleased to announce that smart accounts have been activated on Waves MainNet!This has been one of the most hotly-anticipated features to be...

    From: Waves Platform
    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
    Upcoming ICO's
    This week overview
    Token Name Starts
    CDRX (CDRX) logo CDRX (CDRX) 3 days
    SkyMap (SKYM) logo SkyMap (SKYM) 3 days
    Aditus (ADI) logo Aditus (ADI) 4 days
    PlayChip (PLA) logo PlayChip (PLA) 5 days
    Stem Cell (SCIA) logo Stem Cell (SCIA) 5 days
    Nodvix (NVDX) logo Nodvix (NVDX) 6 days
    Cryptocurrency rates
    *Last hour average price&change
    Coin Name Price Hour
    Bitcoin logo BTC $5510.88187999 -0.12%
    Ripple logo XRP $0.4511968924 -0.47%
    Ethereum logo ETH $175.761615023 0.15%
    Bitcoin Cash logo BCH $434.907492617 -0.95%
    Stellar logo XLM $0.2255528153 -0.57%
    EOS logo EOS $4.4711017273 0.27%
    Litecoin logo LTC $42.4582277886 0.13%
    Tether logo USDT $0.9829188574 -0.02%
    Cardano logo ADA $0.0606995027 0.17%
    Monero logo XMR $85.0403081201 -1.92%
    Tronix logo TRX $0.0183693517 -0.35%
    DigitalCash logo DASH $134.947695903 -0.29%