Cardano Smart Contracts 101 — Testnets

Mark Mathis
Coinmonks

--

cardano కోసం చిత్ర ఫలితం
image source

I remember the first time I heard of Cardano. This weird ADA token that was the first new token listing on Bittrex in a while. I was at a birthday party but I posted up in my car with my phone logged into Bittrex and refreshing the ADA page. Bought it and sold it too soon — story of my life as a trader. Fortunately, the story does not end there as I transitioned from trading to actual development on multiple blockchains for the past year. This project has been shrouded by academia and very little in the way of useable products. I have recently been diving into the new KEVM and IELE testnets and learning how to deploy a smart contract on Cardano. Please give me feedback on this article and take everything said here with a large grain of salt!

The Testnets

There are two testnets currently available for the Cardano platform. Below are the explanations from the IOHK(The company contracted to manage the Cardano development) site.

KEVM TESTNET

Here you will find information and instructions for developers who wish to use the KEVM, a correct-by-construction version of the Ethereum virtual machine (EVM) specified in the K framework. It allows developers to experiment with any smart contract that can be run on the EVM, and offers improved security and performance. K is a means to formally verify software so the code can be automatically checked for any flaws, and can be proven to run exactly as it should. We encourage you to read the detailed documentation on the KEVM and its differences compared to the EVM. Most importantly, we look forward to your feedback.

Source: https://testnet.iohkdev.io/goguen/kevm/

IELE

IELE is a dedicated virtual machine that provides a foundation for the Cardano blockchain protocol. It executes and verifies smart contracts as well as providing a human-readable language for blockchain developers. IELE was designed using formal methods to address security and correctness concerns inherent in writing Solidity smart contracts in Ethereum. When you write a smart contract in IELE, it is more secure and is easier to verify for correctness. You benefit from an easy-to-use and readable language structure — and the overall performance is improved.

The IELE testnet provides better performance and is register-based, which means it can make use of a wider array of analyses and optimizations than a stack-based virtual machine such as KEVM. This leads to more accurate gas cost predictions, as well as lower gas cost for contracts.

IELE is a human-readable language that resembles the LLVM intermediate representation. This makes it easy to code directly to IELE, as well as to understand contracts and how they are deployed in the blockchain. IELE is designed to make formal verification of smart contracts easier. This includes writing specifications that smart contracts must obey as well as helping develop automated techniques that prove smart contracts are mathematically correct. For example, pushing a possibly computed number on to the stack and then jumping to it as an address makes verification hard, and thus security weaker, with current smart contract paradigms. IELE avoids this problem. It has named labels and jumps can only be made to those labels. Also, avoiding the use of a bounded stack and eliminating stack or arithmetic overflow helps the specification and verification of smart contracts.

Debugging contracts is easier because IELE has a different status error code for each of the exceptions that can occur while executing the functions within a contract. The sender of a transaction that calls a function receives a status code as a return value in addition to the normal return values of the account call.

Source: https://testnet.iohkdev.io/goguen/iele/

My Translation

I worked at IBM as an intern when I was in college and one thing we’d do to the new guy was to send him around the lab looking for a 1-D-10-T cable. He would wanted around the lab asking his new colleagues for a 1D10T cable for about 20 minutes until someone told him it was a joke. As a true ‘Idiot’ cable searcher myself, here is my understanding of the two testnets:

KEVM

This testnet is essentially the ETC(Ethereum Classic) EVM, but it’s an EVM(Ethereum Virtual Machine) that has been modified to conform to the K Framework. The K Framework is described here, but it is essentially a standard that a programming language must adhere to in order for its programs to be formally verified and proven. Cardano took the EVM from ETC, added the necessary functions to satisfy the K Framework, and added a K to it — resulting in a correct-by-construction version of the EVM name, KEVM. The KEVM is also a stack-based machine as opposed to our next testnet, IELE, which is a register based machine.

*I found this post on stack/register differences to be insightful and simple

IELE

The IELE testnet is based on a completely different virtual machine than the KEVM. While they both can run Solidity code, the IELE testnet will transform the code down to its own IELE language. IELE serves as a uniform, lower-level platform for translating and executing smart contracts from higher-level languages. The IELE language is human readable and has a unique error code for each type of exception(Goodbye, old friend, VM Exception while processing transaction: revert). The IELE language allows formal verification of smart contracts and it also conforms to the K Framework. For our purposes, we will be writing Solidity code, but it is worth noting that the code ultimately running on the VM will be converted to IELE before execution.

IELE Source: https://runtimeverification.com/blog/iele-a-new-virtual-machine-for-the-blockchain/

Mallet

Mallet is a node CLI tool for interacting with the Cardano testnets. It can also be included as a library in your dApp for chain interaction. In this article, we will use it as a CLI and do some simple account interaction.

Setup

You will need to run mallet with Node 10.4 or above. Most people are running Node 9.x — I would recommend installing NVM(Node Version Manager) via homebrew and managing node versions that way.

NVM Setup

brew install nvm# Add nvm environment variables to your shell 
echo "export NVM_DIR='$HOME/.nvm'" >> ~/.bash_profile
echo ". '/usr/local/opt/nvm/nvm.sh'" >> ~/.bash_profile
# Load variables in current shell
source ~/.bash_profile
# Install 10.4 version of Node
nvm install 10.4
# Verify Version
nvm version

Mallet Installation

# Go to a Projects dir
cd <Cool Projects Dir>
# Pull Mallet
git clone https://github.com/input-output-hk/mallet && cd mallet
# Install dependencies
npm i
# Verify installation
./mallet --help

Testnet Connection

# Connect to the KEVM testnet
./mallet kevm
# Connect to the IELE testnet
./mallet iele
# In both cases, once connected you will see the 'mallet> ' cursor
# indicating you are connected and it is waiting for input

Basic Account Commands

# The account commands are the same for both KEVM and IELE# Create an Account - note we are assigning a variable to use later
mallet> account1 = newAccount(<secret password>)
# List accounts
mallet> listAccounts()
# Select account - note we are using our variable we set earlier
mallet> selectAccount(account1)
# Get balance - no argument assumes you are using the selected acct
mallet> getBalance()
# Request Funds from faucet - note we are using the selected acct
mallet> requestFunds()

Summary

In this article we learned the basics of the Cardano testnets, KEVM and IELE. The Cardano documentation is growing daily and there is evidence of an awesome product there. Hopefully you learned enough to whet your appetite for more as I’ll be showing you how to deploy your first Cardano smart contract to the testnets in the next article!

Get Best Software Deals Directly In Your Inbox

--

--