Lecture 14 Ethereum - Development Environment
Lecture 14 Ethereum - Development Environment
Lecture 14
Ethereum
Development Environment
Lecture 14 – Ethereum - Development Environment
contract SimpleStorage {
uint storedData;
Compile/Deploy/Interact?
• We know how to do this? Once deployed, we will
have a contract address and we can make
transactions.
Modifying Contracts?
• Contracts are immutable so is our blockchain.
• Contracts cannot be changed, we need to
deploy a new one*.
Ethereum Wallet
• Meta Mask - https://metamask.io/
– "MetaMask is a bridge that allows you to run Ethereum dApps
right in your browser without running a full Ethereum node."
Lecture 14 – Ethereum - Development Environment
Ethereum Wallet
• Once installed as a browser extension, it allows to
connect to multipile etherum networks
Lecture 14 – Ethereum - Development Environment
Ethereum Wallet
• Once installed as a browser extension, it allows to
connect to multipile etherum networks
Local blockchain
• How about a local pre-loaded Ethereum chain
with addresses, ethers and ability to view blocks,
transactions ...
Ganache
• Ganache is a personal blockchain for Ethereum development you
can use to deploy contracts, develop your applications, and run
tests.
1. Install Ganache
• Download the appropriate version for your OS from
https://www.trufflesuite.com/ganache
2. Create a Workspace
Lecture 14 – Ethereum - Development Environment
Main Interface
Lecture 14 – Ethereum - Development Environment
Ethereum IDEs
• Remix – Web based IDE http://remix.ethereum.org/
Lecture 14 – Ethereum - Development Environment
Ethereum IDE
• Remix allows to compile, deploy and invoke
smart contracts.
• Smart contracts are immutable, it is less efficient
to do things manually
Lecture 14 – Ethereum - Development Environment
Contract at Ganache
• First look, there is a new block
Lecture 14 – Ethereum - Development Environment
Contract at Ganache
• What does the new block contain?
Lecture 14 – Ethereum - Development Environment
Contract Address
Lecture 14 – Ethereum - Development Environment
Ethers to Faucet
Lecture 14 – Ethereum - Development Environment
...back at Ganache
Lecture 14 – Ethereum - Development Environment
Contract deployment
• It quickly becomes tedious and limiting to do things all
over again.
• A tool, development environment to automate stuff would
make life much easier.
Lecture 14 – Ethereum - Development Environment
Truffle
• "Sweet Tool for the Smart Contracts"
• A development environment for blockchains using the
Ethereum Virtual Machine (EVM), aiming to make life as
a developer easier.
npm
• npm is a package manager for the JavaScript
programming language.
• It is the default package manager for the JavaScript
runtime environment Node.js.
• It consists of a command line client, also called npm, and
an online database of packages, called the npm registry.
Lecture 14 – Ethereum - Development Environment
Javascript
Lecture 14 – Ethereum - Development Environment
Javascript
• We can place the script in the HTML Head or Body.
Placement at the end of body improves performance.
<script src="myScript.js"></script>
Lecture 14 – Ethereum - Development Environment
Javascript
<script>
var person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
alert(person.fullName())
</script>
Lecture 14 – Ethereum - Development Environment
Javascript
<!DOCTYPE html>
<html>
<body>
<p>When you leave input field, a function transforms text to upper case.</p>
<script>
function myFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</body>
</html>>
Lecture 14 – Ethereum - Development Environment
JSON
(JavaScript Object Notation)
Lecture 14 – Ethereum - Development Environment
Example
{"firstName": "John", This is a JSON object
"lastName" : "Smith",
with five key-value pairs
"age" : 25,
"address" : Objects are wrapped by
{"streetAdr” : "21 2nd Street", curly braces
"city" : "New York",
There are no object IDs
"state" : "NY",
”zip" : "10021"}, Keys are strings
"phoneNumber": Values are numbers,
[{"type" : "home",
strings, objects or
"number": "212 555-1234"},
{"type" : "fax",
arrays
"number” : "646 555-4567"}] Ararys are wrapped by
} square brackets
Lecture 14 – Ethereum - Development Environment
A Webserver
var http = require("http");
//hello-world.js
upper = require("upper-case")
console.log(upper("Hello World"));
Lecture 14 – Ethereum - Development Environment
module.exports = function(deployer) {
// deployment steps
deployer.deploy(MyContract);
};
Lecture 14 – Ethereum - Development Environment
Deployment Script
• To deploy two contracts
var ContractOne = artifacts.require("ContractOne");
var ContractTwo = artifacts.require("ContractTwo");
Deployment Script
deployer.deploy(ContractOne).then(function() {
return deployer.deploy(ContractTwo, ContractOne.address);
});
Lecture 14 – Ethereum - Development Environment