September 3, 2026

Smart Contracts in Waves. First experience – Alejandro Escandon

Smart Contracts in Waves. First experience – Alejandro Escandon

In April 2018, the Waves team unveiled their non-turing-complete smart contracts.

A little later, when the Waves Hackathon was announced, it was time to dive into the new technology. Below you will find detailed information about the smart contract that won the third place on the hackathon.

The article will be useful for developers to implement their own smart contracts and get acquainted with the technology.

Idea

The idea of the project is to automatically distribute the salaries of software developers using Github, in proportion to the work performed. The main task that the smart contract solves is that it saves us from having to trust the money-distributing program, allows even the user without programming skills to check the correctness of the distribution of funds before transferring money

Used technology

Html and JavaScript (Node.js Waves library), open source code on GitHub and demonstration of the project on Firebase Hosting.

Process

  1. The user selects the GitHub repository and determines the total amount of salaries.
  2. The user makes a payment in 0.01 Waves (approximately $ 0.02) to create a smart contract and save data in the blockchain.
  3. The user checks the accuracy of the data and then transfers the amount of salaries to the address of the smart contract.
  4. Salaries are distributed among developers.

Development

The best entry point for a novice developer is the developer ide, containing examples and a console for testing code. During development, it is better to use the testnet wavesexplorer, where you can get 10 free testnet waves with one click. And although in Google still does not find many examples because of the new technology, waves smart contracts are well documented and contain all the necessary information.

The Waves API library for Node.js already works well in browsers, but unfortunately, it is NOT yet compatible with Google Cloud Functions or React Native (the Waves developers are working to fix it soon).

Smart Contract

A smart contract is created for one account and checks every action with that account (except for incoming money transfers):

Analysis of each line of code of the smart contract

Here we save the public key of the wallet (your JavaScript must contain the publicKey variable created), so that only the smart wallet contract account (Smart Rewarding Project in our case) can transfer funds.

This is the basic structure of any smart contract. Waves tells us that this contract prohibits any activity case _ => false except transfer of funds case tx: TransferTransaction. Therefore, after creating a contract, it is impossible to change the data of the developers who will receive the money (through DataTransaction) or change the smart contract itself (through SetScript).

Here, the built-in library’s base addressFromPublicKey method is used to obtain the address of the request creator from its public key.

The base method addressFromRecipient gets the address of the recipient of funds.

The base getInteger function gives us the data stored in the blockchain at the address of the request creator, the employer, which is the sum of the developer’s salary, it get data from the employer account state. The contract can access data stored on the Waves blockchain (and can NOT access data located on any website or a third-party server).

Here is the verification of the amount and the signature. True means that the transaction will be allowed, and false means that the transaction will be denied. Thus, any transfer of money from this account is checked and the money will be sent only to the developer’s wallet and to the amount already stored in the blockchain in the format of an easily readable pair of keys (address as key and amount as value), which allows to trust the dapp.

Online demonstration of the project on a testnet waves platform, available here.

Here you can see the project code.

I hope that the article was informative and will be useful to you for writing your first smart contract.

Want to learn more, go to the online free course Mastering Web3 with Waves.

Published at Wed, 10 Jul 2019 22:54:12 +0000

Previous Article

Blockstack Is Planning One of the First Reg A+ Compliant Token Offerings In the US

Next Article

Bitcoin Price Breaks Below $12,000 As Crypto Market Bleeds Over $25 Billion