You are on page 1of 27

Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.

Global Open Versity


Blockchain DevOps Hands-on Labs Training Manual

Step-By-Step Guide on Deploying Revenue Sharing Blockchain Smart


Contracts using Remix-IDE on Windows
Kefa Rabah
Global Open Versity, Vancouver Canada
krabah@globalopenversity.org
www.globalopenversity.org

Table of Contents Page No.

STEP-BY-STEP GUIDE ON DEPLOYING REVENUE SHARING BLOCKCHAIN


SMART CONTRACTS USING REMIX-IDE ON WINDOWS 3

Introduction 3
What is Dapps? 3
What qualifies as a Dapp? 4
Picking what to learn: Decentralized Applications 4

Smart Contracts 4

Ethereum: Decentralized Applications 5


Gas and Gas Costs 5

Hands-on 6

Part 1: Install Blockchain Required Tools 6

Part 2: Get started with Solidity and Smart contracts 7


Step 1: Installations of Tools 7
Step 2: Install Lightweight http-server 7
Step 3: Install Remix 7

Part 2: How to Code a Dapps 9


Step 1: Using Remix-IDE 9
Step 2: Compile the Contract 15

Part 3: Deploy the Contract 17


Step 1: A Glimpse inside Run Tag 17
Step 2: Deploy the Contract 18

Part 4: Interacting with Deployed Contract 22


1
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Step 1: Check Variables 22


Step 2: Execute shareRevenue() Function 23

Part 5: Transaction Log 24

Part 6: Summary 25

Congratulations! 26

A Globalopenversity Open Access Technical Academic Publications


Delivering Cutting-edge Technology at your Fingertips in the 21st Century
2
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Global Open Versity


Blockchain DevOps Hands-on Labs Training Manual

Step-By-Step Guide on Deploying Revenue Sharing Blockchain Smart


Contracts using Remix-IDE on Windows
By Kefa Rabah, krabah@globalopenversity.org April 16, 2018 The Lake Institute

Introduction
In this Hands-On guide you will learn how to get started learning on how to code a Decentralized
Applications or Dapps and what are the things that you must cover when making one. It’s important to
keep in mind that this field is constantly evolving and that it is always a good idea to keep refreshing your
knowledge about whatever you learn.

Blockchain has been around for about a decade now. Blockchain technologies and how it works, is the
next big thing to shape our lives and our futures. Blockchain lets us for the first time to have a shared
version of truth that is open, distributed and tamper proof in its nature. Blockchain has these properties
because at the heart of it, it has a way to derive consensus (thereby having a shared version of truth) and
also has cryptography baked into it by design (thereby letting us have a tamper proof record), and more
importantly it’s decentralized – i.e. it’s not controlled by any central authority or government.

Blockchain has a wide ranging set of applications and almost any field can benefit from having such a
technology at its disposal, as you must by now have learned from our Part 1 of this book. Blockchain is
also heralded as a way by which trust can be ensured in the online world and lets us have greater
confidence in the range of products and services that we use online.

However, it isn’t quite enough to know about the properties of blockchain and how it will impact the world
around us. To get a thorough understanding of the blockchain it is essential to know how to interact with it
programmatically and thinking about solutions from the software development aspect that we are used to.
Developing applications on the blockchain is certainly something that is new and cutting edge – in fact,
there is a new word to describe the type of applications that are powered by the blockchain. These are
called Decentralized Applications or Dapps.

What is Dapps?
Dapps are a new way about thinking about how we can go about writing applications for the internet that
powers blockchain technologies and applications. While previously we would have the backend code
residing in a server or a set of servers, Dapps let us run web enabled applications where the backend is
hosted and that is on a blockchain network, which executes the code that is needed for it.

3
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

What qualifies as a Dapp?


If you look online, the word Dapp is itself is not precisely defined and can often mean different sets of
things to different people. However, David Johnston has done work in formalizing the process of what a
Dapp is and what its characteristics should be. The two main points that we would like to focus on is: Link:
https://github.com/DavidJohnstonCEO/DecentralizedApplications/blob/master/README.md
1. The application’s source code must be open sourced.
2. The application’s data and records must be stored on a public blockchain.

Picking what to learn: Decentralized Applications


As with any programming concept or idea, there are a wide range of platforms available to code on when
talking about blockchain. While each platform has its pros and cons, it is important to also see how your
application is structured so that you use the appropriate services at each of these stages.

As we are familiar with modern computing, it is important to have all the required components of a tech
stack with their counter parts in the decentralized world. However, it is not trivial to find out and do
research on each of the components. Thankfully, there is this handy info graphic that we can use to get a
sense of the ecosystem:

Table 1: Comparison of web services

Web 2.0 Web 3.0 (dApps)


Scalable computation Amazon EC2 Ethereum, Truebit
File storage Amazon S3 IPFS/Filecoin, Storj
External data 3rd party APIs Oracle (Augur)
Monetization Ads, selling goods Token model
Payments Credit Cards, PayPal Ethereum, Bitcoin, state channels, Ox
Source: https://medium.com/@FEhrsam/the-dapp-developer-stack-the-blockchain-industry-barameter-
8d55ec1c7d4

As we can observe, we have solutions for computing, file storage, API calls (external data), monetization
and payments. In this guide we are mainly going to be focused on ethereum and how we can tackle the
computing aspect of Dapps. Since computing is one of the most important aspects of building dapps, it
makes sense to get familiar with interacting with smart contracts and then proceeding further.

Smart Contracts
The term Smart contracts was coined by Nick Szabo in 1994. Smart contracts and blockchain are closely
linked – smart contracts are the programs that we write on the blockchain and let us interact with it. It is in
a smart contract that we can define business logic and let us code the rules with which we want to interact
with the blockchain. The most powerful feature of a smart contract is the fact that once it is deployed on to
the blockchain, it is immutable and you cannot go back and edit the programs. This makes us embrace a
paradigm where we have a piece of code with the logic that we want in it will be immutable and can be

4
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

execute by itself when it is called. It is smart contracts that truly unleash the power of the blockchain, and
hence, it is important to learn to develop smart contracts on the blockchain.

Ethereum: Decentralized Applications


Ethereum is probably the most popular blockchain platform that exists right now. They have had a public
release for more than 3 years and it has a thriving community that maintains the project. They also have
developed their own programming language called Solidity that lets us interact write smart contracts.

Ethereum has a public blockchain that lets people run code on and it one of the simplest way to start
programming on the blockchain.

Gas and Gas Costs


The Ethereum blockchain has a concept of Gas and Gas costs that is a very important to understand
before you can start coding on it.

Gas is amount of fuel that you need to pay to get your transaction executed. The transaction could either
be deploying your contract on the blockchain or can be running a function that already exists. Every time a
function is called, there is some code that is executed. This code is executed on the computer of the
person who is mining the transaction and requires computation power – to incentivize people to share
their computational power and execute the transaction; each operation is charged some gas depending
on the complexity of the transaction. The Gas in an ethereum smart contract can range all the way to 21
million. The gas that your transaction needs is multiplied by the gas cost to get the gas price.

5
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Gas price is paid in ether, and hence, it is important to make sure that you have the correct balance in
your account to deploy the contract on the blockchain. This is why instead of developing on the main
network (which costs ether), we will run our code on a local instance of the ethereum virtual machine.
Another interesting facet of this is that while coding, you would want to structure your program in a way
that reduces your overall gas cost.

Hands-on
In this Hands-On guide you will learn how to get started learning on how to code a Decentralized
Applications or Dapps and what are the things that you must cover when making one. It’s important to
keep in mind that this field is constantly evolving and that it is always a good idea to keep refreshing your
knowledge about whatever you learn.

Pre-requisite or the Hands-on Labs


This tutorial requires that you already have some knowledge of Truffle, Ethereum, and Solidity. You can
start with this tutorial to get yourself up to-speed, check our Blockchain Labs Tech Series to quick you a
quick start:

1. https://www.scribd.com/document/373203852/Step-By-Step-Guide-Installing-Ethereum-Building-
a-Blockchain-on-Ubuntu-16-04-Linux-Server

2. https://www.scribd.com/document/373203852/Step-By-Step-Guide-Installing-Ethereum-Building-
a-Blockchain-on-Ubuntu-16-04-Linux-Server

3. https://www.scribd.com/document/374058743/Step-By-Step-Guide-Building-Deploying-a-Private-
Blockchain-Network-on-Windows

4. https://www.scribd.com/document/375953366/Developing-Smart-Contract-on-Ethereum-
Blockchain-Using-Truffle-Framework

Part 1: Install Blockchain Required Tools


The tools we will use
The most prominent tools at the moments are:
• Truffle: A development environment, testing framework and asset pipeline for Ethereum. In other
words, it helps you develop smart contracts, publish them, and test them, among other things. You
can read the docs of the Truffle suite for more informations.
• Ganache: It was called TestRPC before, if you have read a tutorial from a few months ago, chances
are they use TestRPC with Truffle, but it was renamed upon the integration of TestRPC within the
Truffle Suite. What Ganache does is simple, it creates a virtual Ethereum blockchain, and it generates
some fake accounts that we will use during development.

• Mist: It’s a browser for decentralized web apps. It seeks to be the equivalent of Chrome or Firefox, but
for Dapps. It’s still insecure and you shouldn’t use it with untrusted dapps as of yet.

6
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

• Ethereum wallet: It’s a version of Mist, but only opens one single dapp, the Ethereum Wallet. Mist and
Ethereum Wallet are just UI fronts. And we need a core that will connect us to an Ethereum
blockchain(It could be the real Ethereum blockchain, or a test one).
• Geth: Is the core application on your computer that will connect you to a blockchain. It can also start a
new one (in our case we will create a local test blockchain), create contract, mine ether etc.

Part 2: Get started with Solidity and Smart contracts


We’re going initially install our required tools for this Hands-On

Step 1: Installations of Tools


1. The requirements for this tutorial are that you know what is and how to use a command-line tool, and
you are a bit familiar with NPM, which we must download and install first. At the time of writing this
article, we used “node-v9.8.0-x64.exe”

Step 2: Install Lightweight http-server


This a lightweight server that we’ll use to host your web app locally as you develop on localhost:8080.

2. Type the following command to install the server:

npm i -g http-server

3. You’re done with this section.

Step 3: Install Remix


4. Install npm and node.js (see https://docs.npmjs.com/getting-started/installing-node), then do:

5. Remix-ide has been published as an npm module:

npm install remix-ide -g

7
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Or if you want to clone the github repository:

git clone https://github.com/ethereum/remix-ide.git


cd remix-ide
npm install
npm run build && npm run serve

6. Start the Remix IDE

remix-ide

Note: Remix IDE requires Apache (http) server to be in place.

Note: the "ballot.sol" is a default file that come with Remix IDE. So go ahead and overwrite it.

8
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

7. To stop the server, issue ^C command:

Remix is a suite of tools to interact with the Ethereum blockchain in order to debug transactions
(directly quoted from here). There is an IDE version (Remix IDE) and an online version, which we will
use here.

There are many tools inside Remix, but the following tools are of our interests,
• Solidity Compiler. which generates a lot of useful information that we will use in another
environment
• Runtime Environment. Remix provides three:
o Injected Web3: to provider such as Mist or MetaMask
o Web3 Provider: to local host through ipc
o JavaScript VM: a simulated environment

Among the runtime environments, we are using JavaScript VM. In the JavaScript VM, Remix comes
with five Ethereum accounts, each of which is deposited with 100 ethers. This is good enough for
testing our smart contract. Also, mining is not required as it is done automatically.

8. You’re done with this section

Developing Contract using Remix


9. Run npm start and open http://127.0.0.1:8080 in your browser.

10. Then open your text editor and start developing. The browser will automatically refresh when files
are saved.

Note: most of the time working with other modules (like debugger etc.) hosted in the Remix repository
is not needed. But in case changes have to be made in that repository too, the following command will
help you link Remix with your local remix-ide repository:

11. You’re done with this section

Part 2: How to Code a Dapps

Step 1: Using Remix-IDE


The ethereum foundation has released a cloud based IDE called Remix that is a simple way to get
started, and which we have now installed and working.
9
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

The simplest thing to do in any programming language is declare and write variables so let’s see an
example of how to do that is to simple use the existing default Solidity file Ballot.sol., which have
copied and pasted here or brevity:

pragma solidity ^0.4.0;

contract Ballot {

struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
uint voteCount;
}

address chairperson;
mapping(address => Voter) voters;
Proposal[] proposals;

/// Create a new ballot with $(_numProposals) different proposals.


function Ballot(uint8 _numProposals) public {
chairperson = msg.sender;
voters[chairperson].weight = 1;
proposals.length = _numProposals;
}

/// Give $(toVoter) the right to vote on this ballot.


/// May only be called by $(chairperson).
function giveRightToVote(address toVoter) public {
if (msg.sender != chairperson || voters[toVoter].voted) return;
voters[toVoter].weight = 1;
}

/// Delegate your vote to the voter $(to).


function delegate(address to) public {
Voter storage sender = voters[msg.sender]; // assigns reference
if (sender.voted) return;
while (voters[to].delegate != address(0) && voters[to].delegate !=
msg.sender)
to = voters[to].delegate;
if (to == msg.sender) return;
sender.voted = true;
10
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

sender.delegate = to;
Voter storage delegateTo = voters[to];
if (delegateTo.voted)
proposals[delegateTo.vote].voteCount += sender.weight;
else
delegateTo.weight += sender.weight;
}

/// Give a single vote to proposal $(toProposal).


function vote(uint8 toProposal) public {
Voter storage sender = voters[msg.sender];
if (sender.voted || toProposal >= proposals.length) return;
sender.voted = true;
sender.vote = toProposal;
proposals[toProposal].voteCount += sender.weight;
}

function winningProposal() public constant returns (uint8 _winningProposal) {


uint256 winningVoteCount = 0;
for (uint8 prop = 0; prop < proposals.length; prop++)
if (proposals[prop].voteCount > winningVoteCount) {
winningVoteCount = proposals[prop].voteCount;
_winningProposal = prop;
}
}
}

12. From the code, there are two functions – one that lets us set the variable value and one that lets us
read it.

• The first line of code tells us that we using a particular version of Solidity.
• The contract SimpleStorage tells us the name of the contract and it helps us group code and
logic into a single unit that can be referenced directly.
• The next line of the code declares a variable – storeData is of type unit.

Note: the next two functions are simply getter and setter functions of the variable storeData.

13. On Windows, from Start Run CMD, you can start the Remix IDE, as follows:

remix-ide

11
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

14. Next, fire-up your browser and point it to URL: http://locahost:8080

Fig. 3

The screen is divided into several areas.


• Area for Smart Contract: we are pasting the Solidity code of contract here.
• Area of Compilation and Runtime: in Compilation tag, here show any compilation errors or
warnings. in Run tag, we deploy the contract and execute contract functions.
• Area of Transaction Logs: all transaction detail can be observed here.

Note: let’s take a minute to see what happens when we click on the Create button. Every time you
click on create, you are taking your Solidity based smart contract and deploying it on the blockchain.
However, to simplify things and make it faster to develop applications, the blockchain that it deploys to
is the ethereum virtual machine and resides in your browser and lets you interact with it. Since code
once deployed cannot be changed, each time you have to make a change to your code, you have to
redeploy it and test it out again

15. From the button click on the Detail link

12
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Fig. 4

16. Which we can now observe as shown in Fig. 5.

Fig. 5

Note 1: the console output that you see when you create the smart contract.

13
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Note 2: all you need to do is to deploy to the mainnet blockchain (the actual ethereum blockchain) is
change the environment in the run tab and you should be able to write to the blockchain – keep in
mind that interacting with the ethereum main-net will actually cost you money and every time you call
a function or deploy a new contract, you have pay a gas cost in ethereum to make sure that your
contract or function call gets mined and that you get your output.

Note 3: once you are up and running with Ethereum, you can read up the Solidity documentation to
get yourself familiarized with the platform and its syntax, and it will form the core task on our next
Hands-On Lab. Solidity is fairly easy to learn and is very similar to javascript in its syntax. Let’s have a
look at another Solidity example code to give a better feeling of what programming on it looks like.
This one lets us conduct an open auction in a fair manner:

pragma solidity ^0.4.8;

contract RevenueSharing {
address public creator;
mapping(uint => address) public shareholders;
uint public numShareholders;

event Disburse(uint _amount, uint _numShareholders);

function RevenueSharing(address[] addresses) {


creator = msg.sender;
numShareholders = addresses.length;
for (uint i=0; i< addresses.length; i++) {
shareholders[i] = addresses[i];
}
}

function shareRevenue() payable returns (bool success) {


uint amount = msg.value / numShareholders;
for (uint i=0; i<numShareholders; i++) {
if (!shareholders[i].send(amount)) revert();
}
Disburse(msg.value, numShareholders);
return true;
}

function kill() {
if (msg.sender == creator) selfdestruct(creator);
}
}

Some quick points about this contract:

• The contract is named RevenueSharing.

• Function RevenueSharing() has the same name of the contract itself. It is the
constructor, and only called once when the contract is deployed. We see in this contract an
array of addresses is supplied, and this array of addresses are stored in another array called
shareholders.

14
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

• Function shareRevenue() is the only main function in this contact. When executing this
function with an amount of ethers (in msg.value), the amount is divided into the number of
shareholders (numShareholders), and each address in the shareholder array will get the
portion. We will execute this function in our demo.

• Function kill() is used for removing the contract. We will not use this function in the
demo.

Note: that all variables are defined with public. This helps us to observe more detail in the contract.
In real life, we should be careful when making variables or functions public due to security
consideration.

17. You’re done with this section.

Step 2: Compile the Contract


1. We paste the Smart Contract code in Remix, as shown in Fig. 6.

Fig. 6

The screen is divided into several areas.


• Area for Smart Contract: we are pasting the Solidity code of contract here.
• Area of Compilation and Runtime: in Compilation tag, here show any compilation errors or
warnings. in Run tag, we deploy the contract and execute contract functions.
15
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

• Area of Transaction Logs: all transaction detail can be observed here.

The we’re noticing in Fig. 6a, at time comes about because of wrong Remix version, if we go to Setting
button and choose, the correct version here solidity ^0.4.10; then as can be observed, all the errors are
longer there! Also ensure to check Enable Optimization, while there, Fig. 6b.

Fig. 6a

Fig. 6b

Note:
If we click Details link, we will see a lot of information for this contract. Among them they are,
• Bytecode
• ABI

16
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

• Web3 Deploy

They are needed when deploying this contract in another environment. We will refer this back later.

2. You’re done with this section.

Part 3: Deploy the Contract

Step 1: A Glimpse inside Run Tag


It is how it looks like inside the Run tag.

Fig. 7

From the Environment, choose JavaScript VM.

Fig. 8

After selecting JavaScript VM, we will see some accounts are populated in Account fields.

17
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Fig. 9

And as said, each of which are pre-deposited 100 ethers, just for testing. As we will use these accounts
later, we can copy them first.

Fig. 10

The Gas limit is to specify how much gas we can spend on any transaction. As we are in test
environment, we do not worry this too much. I have tried some big contract deployment and the default
gas limit is not adequate. Anyway, it can be increased to whatever value when needed.

The Value part is where we send the amount of ethers during contract deployment and executing a
function. In our case, we do not put any value in contract deployment, but put some ethers when
executing the function. See below for more detail.

Step 2: Deploy the Contract


3. Now we see the contract RevenueSharing is already selected (we have only one contract in our
code). We will use Create button to deploy this contract onto the JavaScript VM.

Fig. 11

4. Something is required, as hinted in the input area: “address[] addresses”, when the contract is
deployed. Remember this contract requires a list of addresses as sharing targets? For demo purpose,
we will use the 3rd, 4th and 5th addresses listed above as the address list. So paste this beside the
Create button:

["0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db",
"0x583031d1113ad414f02576bd6afabfb302140225","0xdd870fa1b7c4700f2bd7f44238821c26f73921
48"]
18
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

5. Now make sure we have selected


• Environment: JavaScript VM
• Account: the first account when deploying this contract (begins with 0xca3…)
• Paste the address array above beside Create button

Fig. 12

6. Click on “Create” under your “Run” tab. You should now see your contract created just like below.

Fig. 13

19
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Note: the amount of ether on our account ticked down slightly from 100 after creating the contract.

7. Right off the bat you can see the 3 functions that we had created — “kill”, “shareRevenue”, and
“creator”, and “numShareholders”, “shareholders”. You can also see that our state variable
has a value assigned to it of Uint256.

Fig. 14

8. Now, click “shareholders” which display the changes as shown. Then go ahead and click
“numshareholders” to call our newly modified content displayed.

Fig. 15

20
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Fig. 16

The contract is now deployed in JavaScript VM (memory), and the contract address is shown (0x692…).
We do not use this address in our demo. That address can be referred in other cases when needed.

Also, we see the variables marked as “public” is now shown, they are,
• shareholders
• numShareholders
• creator

And two functions we have defined in this contract,


• shareRevenue()
21
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

• kill()

Before everything, we observe that the account balance is reduced by a small amount of ethers. The
difference (417,626 weis, 1 wei = 10-18 ether) is the cost of deploying this contract. In real life, it is the
real ethers deducted from your account when you deploy a contract.

9. You’re done with this section.

Part 4: Interacting with Deployed Contract


1. Ensure that the Accounts section has the first account selected.

Fig. 17

2. You’re done with this section.

Step 1: Check Variables


3. We can first check the variables by pressing the variable buttons. Here we examine the
numShareholders and creator. For shareholders, as it is an array, we need to specify an index (0, 1
or 2), corresponding to the addresses we put when the contract is deployed (created).

Fig. 18

Note: all the variables are as what we had expected.

22
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

4. You’re done with this section.

Step 2: Execute shareRevenue() Function


5. Now we execute shareRevenue(). We use the first account to deposit 30 ethers when executing
this function (This is only for this function. In many cases this is not required.). According to the
contract logic, the 30 ethers are to be distributed among the account list, that is, the 3rd, 4th and 5th
account in our account list. As of now, the balance of each of them is still 100 ethers.

We use the same place to execute the function. Here we make sure to,
• in Account field, choose the first account (begins with 0xca3…)
(0xca35b7d915458ef540ade6068dfe2f44e8fa733c)
• place 30 ethers in the Value

Fig. 19

23
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

6. Then press shareRevenue. After the function is executed, we examine the balance of each
accounts, and see if it is executed according to our design.

First, we see 30 ethers are deducted from 1st account, and all the three accounts on the list now have
110 ethers. So the 30 ethers deducted from 1st account is now distributed among the three accounts.
This part works perfects according to the contract.

Also, if we closely examine the balance of 1st account, some additional amount of ethers is deducted.
The difference is 47,776 wei, which is the cost for this transaction. Every transaction, execution of
function, or deployment of contract costs you some amount of ethers.

7. You’re done with this section.

Part 5: Transaction Log


1. We have not touched the transaction log during our test, but everything is kept in log, even the inquiry
of a variable. Let us take a look on detail from two selected logs.

Fig. 20

24
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

We can see who has deployed this contract, the contract address, and the transaction cost required to
deploy it.

2. Execution of shareRevenue() function


2. The shareRevenue transaction log from Remix-IDE.

Note: again we see it as a transaction cost. In shareRevenue(), there is a return boolean value and
we see the “decoded out” there is a “true” return. Also, we have an event for successful distribution
and we see it inside “logs”.

3. You’re done with this section.

Part 6: Summary
This is how Remix helps in testing the code we develop. It comes with very handy features and intuitive
user interface. In next Hands-On Labs we will use another environment, testrpc (or ganache-cli), to
work on the same contract and see how it works.

25
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org
Global Open Versity Deploying Revenue Share Smart Contracts using Remix-IDE v1.0

Congratulations!
Congrats on finishing the tutorial on Revenue Sharing and having deployed and interacting with the smart
contract! This is your first time to learn on how Remix helps in testing the code that you have developed. It
comes with very handy features and intuitive user interface. Again, lots of details and tools, but hope that
some of these made sense, and gave you a little more clarity on how blockchain smart contract work.
Plenty more to do and learn now that you know the basics.

Available from Scribd.com:

A Creative Common Publication:

-----------------------------------------------
Kefa Rabah is the Founder of The Lake Institute. Kefa is knowledgeable in several fields of Science &
Technology, Information Security Compliance, Blockchain Technology, Distributed Ledger Technology
(DLT) and Project Management, and Renewable Energy Systems. He is also the founder of Global Open
Versity, a place to enhance your educating and career goals using the latest innovations and
technologies.

Fellow us on Twitter: The Lake Institute and Kefa Rabah

A Globalopenversity Open Access Technical Academic Publications


Delivering Cutting-edge Technology at your Fingertips in the 21st Century
26
April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org

You might also like