DIscussion - 10 hours
Professor Michael G. Solomon
BLCN 631 – Blockchain Implementation
EFD Chapter 7 – Building Your First Ethereum Apps
Setting up Your Project
• Everything starts with a project
• We’ll use Truffle to manage projects
• Edit the config file first
• Use VS Code
• Use Ganache settings (next slide, please)
• HOSTNAME
• PORT NUMBER
Ganache – Host & Port
Exploring Ganache
Simple Smart
Contract
• New language – changes frequently
We’ll use the Solidity language
• Blockchain access costs $$ (crypto) • What gets written in a blockchain
• Stays in the blockchain
Remember
• Returns a string – “Hello world!”
First smart contract
HelloWorld.sol
pragma solidity ^0.5.0;
contract HelloWorld {
string private helloMessage = "Hello world";
function getHelloMessage() public view returns (string memory) {
return helloMessage;
}
}
Writing Smart
Contract Code
• Create new file - contracts/HelloWorld.sol
• Create new file - migrations/2_contract_migrations.js
• Type the following code:
var HelloWorld =
artifacts.require("HelloWorld");
module.exports = function(deployer) {
deployer.deploy(HelloWorld);
};
Compiling Smart
Contracts
• EVM can’t run source code
• Smart contracts must be compiled into bytecode
• EVMs run bytecode
• Open new terminal (Terminal -> New Terminal)
• Type: truffle compile
Deploying a Smart Contract
• Make sure Ganache is running
• In VS Code terminal, type:
• truffle deploy –reset
• Go look at Ganache again
• Account[0] balance, blocks, transactions
Invoking a Smart
Contract Function
• Invoke smart contract functions
• At the VS code terminal prompt
• Three separate commands below:
truffle console
HelloWorld.deployed().then(function(in
stance) {return instance });
HelloWorld.deployed().then(function(in
stance) {return
instance.getHelloMessage() });
Summary
Exploring your development environment
Coding in Solidity
Writing smart contracts
Using blockchain data