0% found this document useful (0 votes)
7 views

BlockChain Workshop_Section 2

The document outlines the setup process for Ethereum development, including installing necessary libraries, wallets, and environments such as Node.js, Truffle, Ganache, and MetaMask. It also covers the basics of sending and receiving Ether, including the use of testnets like Sepolia and Goerli, and provides instructions for creating and managing Ethereum wallets. Additionally, it introduces smart contract fundamentals, including their structure, coding in Solidity, and key concepts like storage and memory.

Uploaded by

sree191612
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

BlockChain Workshop_Section 2

The document outlines the setup process for Ethereum development, including installing necessary libraries, wallets, and environments such as Node.js, Truffle, Ganache, and MetaMask. It also covers the basics of sending and receiving Ether, including the use of testnets like Sepolia and Goerli, and provides instructions for creating and managing Ethereum wallets. Additionally, it introduces smart contract fundamentals, including their structure, coding in Solidity, and key concepts like storage and memory.

Uploaded by

sree191612
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 68

Lab Session 2: Ethereum – Part 1

Part 1.1:Setup libraries, Ethereum wallets and environments


Part 1.2: Sending and Receiving Ether
Objectives

• setup your libraries, wallets and environments.


• Sending and Receiving Ether.
Pre-requisties

• Install of all of these for the proper setup.


• Its better to do this on day 1
1. Node.js
- Npm (node package manager) and Nvm (Node Version Manager)
2. Truffle and Ganache
3. Ethereum wallet
4. Chome/Metamask
5. Visual Studio Code
1) Node.js --
https://nodejs.org/en/download/

Latest LTS Version: 18.14.1 (includes npm 9.3.1) as


on 19/2/2023
Node.js – installation
npm/ Node Package manager:
• https://github.com/npm/cli
• https://docs.npmjs.com/cli/install
In the cmd – keyin C:\Users\TAR UC>npm install

You may check whether npm is installed in the PC or not


2) Truffle and Ganache 🡪
https://www.trufflesuite.com/ganache
2) Truffle and Ganache
May encounter this error when install
Ganache… to turn of sideloading

https://docs.microsoft.com/en-us/windows/application-
management/sideload-apps-in-windows-10
• Working on your own device
2) Truffle and Ganache
Solution…. to turn of sideloading in Group Policy
1

2
Solution…. to turn of sideloading in Group Policy
2) Truffle and Ganache
2) Ganache and Truffle
2) Ganache and Truffle
• In the cmd – keyin C:\Users\TAR UC>npm install -g truffle OR
• In the cmd – keyin C:\Users\TAR UC>npm install truffle -g OR
• In the cmd – keyin C:\Users\TAR UC>npm i truffle -g
Verify the truffle installation in Powershell / cmd
prompt using this command truffle version
2) Ganache and Truffle
• In the cmd – keyin C:\Users\TAR UC>npm install -g ganache-cli
3) Ethereum wallet

https://ethereum.org/

Real “Ethereum wallet”


Create Ethereum wallet from MetaMask
Option 1: --Create a wallet from Metamask
Option 1: --Create a wallet from Metamask

Watch this Video


Import to copy and keep this secret backup phase
Option 2: -- if you have the wallet account
before and you can import wallet to Metamask
YOUR Metamask Account passward
• Account Detail
Import/create NEW/second account from
this interface
5) Visual Studio Code
https://code.visualstudio.com/
Part 1.2
Sending and Receiving Ether
Some old test nets
on 19/2/2023
in202301

new test net


https://ethereum.org/en/developers/docs/n
etworks/#ethereum-testnets
•– in 202309
Which Testnet should I use?
• The two public testnets that client developers are currently maintaining are
Sepolia and Goerli. Sepolia is a network for contract and application
developers to test their applications. The Goerli network lets protocol
developers test network upgrades, and lets stakers test running validators.
Grabteeth
• https://grabteeth.xyz/ X
PoW faucet
• https://sepolia-faucet.pk910.de/

FaucETH
• https://fauceth.komputing.org/X
https://sepoliafaucet.com/ 28.11.2023
https://www.infura.io/faucet/sepolia 28.11.2023
https://beyondfaucet.com/sepolia/
- change Account Name
- View your account transaction on Etherscan website
- Export Private Key (remember hide it, don’t let other to see your
private key)
Address of my BMIS2003BAD-chawtv-1
Send the ether from one account to another
account

1 Ether = 1,000,000,000,000,000,000 Wei (10 18


)
Section 2 : Ethereum- Part 2
•2. 1 Smart Contract Basics
•2.2 Smart Contracts Defined
•2.3 Using Remix Browser
•2.4 Write a Smart Contract

(Remix IDE, Greeter.sol, MyContract.sol & simple storage.sol)


• able to explain the elements of a smart
contract
• solve a problem and design a smart
Learning contract solution
• use remix development environment
Objectives for building and testing smart
contracts
• deploy the smart contract using remix
• Custom logic and code deployed
within blockchain environment like
Ethereum

What is • Rules that define interaction


between accounts

a Smart • Transfer and handle digital assets


• Basically a small program with
Contract function that allow you verify
information, facts ,data or balances
• Smart contract allows for complexity
user-defined operations
• transfer of assets other than value or
cryptocurrency
Smart • specification of rules for an operation
on the blockchain.
contract has • implements of policies for transfer of
some assets in a decentralized network.
• It also adds programmability and
advantages intelligence to the blockchain.
… • represents a business logic layer, with
the actual logic coded in a special
high-level language.
Compare Bitcoin transaction and a smart
contract transaction

1. a transaction could embed a function implemented


1. all the transactions are about send value. by a smart contract.
2. Example here is voting smart contract. The functions
are ValidateVoter, Vote, Count, Declare Winner.
What • currency transfer, used to buy a
problem or service, a product, or a utility from a
person or a business.
problems a • Smart contract allows for
smart implementation of rules, policies and
with the help of blockchain, supports
contract the methods for governance and
provenance.
can solve
Using Remix
Browser
Structure of a smart contract
• Smart contract can store variables in it called state variables.
• Contract in the Ethereum blockchain
1. pragma directive (eg: pragma solidity >=0.4.0 <0.8.0;)
2. name of the contract
3. data or the state variable that define the state of the contract,
4. collection of function to carry out the intent of a smart contract.
• Identifiers representing these elements are restricted to ASCII
character set. Make sure you select meaningful identifiers and follow
camel case convention in naming them.
• 3 steps in the development of a smart contract: design, code, and
test.
Create your first Smart Contact from high level
overview of Solidity by using the remix IDE in
your browser.
• Create smart contract name called Greeter.sol
Exercise 1: • Greeter has a
Greeter.sol • Declare the version of solidity (old) likes
^0.5.0
• Declare string state variable named
yourName
• Create constructor() function for this
Greeter smart contact to set a default value
Constructor() of yourName as “Hello World 123”
• Create set() function to set the name
get ( ): string
• Create get() function that returns a string
name.
• Change the old version of solidity code into
latest version of solidity codes
Exercise 1: • Check up the warning messages and error
Greeter.sol messages in the latest version of solidity
codes
• Solve the errors and update to the latest
version of solidity codes

Constructor() https://docs.soliditylang.org/en/v0.8.19/

get ( ): string
SPDX License Identifier
• https://docs.soliditylang.org/en/v0.6.8/layout-of-source-files.html

// SPDX-License-Identifier: MIT
When to use Storage Vs Memory in Solidity
• You must having knowledge of how your variables and data (storage
layout) are handled by the EVM
• in pragma solidity ^0.5.0 and above
• Memory- temporary place to store data. Smart Contract can use any
amount of memory during the execution but once the execution
stops, the Memory is completely wiped off for the next execution.
• Storage - holds data between function calls. Storage is persistent,
each execution of the Smart contract has access to the data
previously stored on the storage area.
When to use Storage Vs Memory in Solidity
• State variables and Local Variables of structs, array are always stored
in storage by default.
• Function arguments are in memory.
• Whenever a new instance of an array is created using the keyword
‘memory’, a new copy of that variable is created. Changing the array
value of the new instance does not affect the original array.
When to use Calldata in Solidity
• in pragma solidity v0.6.9 and above
• Calldata is only valid for parameters of external contract functions and
is required for this type of parameter. Calldata is a non-modifiable,
non-persistent area where function arguments are stored, and
behaves mostly like memory.
• It is recommended to try to use calldata because it avoids
unnecessary copies and ensures that the data is unaltered.
• For array parameters in functions, it is recommended to
use calldata over memory , as this provides significant gas savings.
1. Declare state variable with public (visibility specifier), then can
remove get() function
string public yourName;

Exercise 2: 2. Set the default value when declare the state variable in the
MODIFY smart contract. Then can remove the default value in the
constructor function
Greeter.sol (in string public yourName = "Hello World 123";
Exercise 1)
3. Declare state variable as constant which don’t want the user
to change this value. Then can remove set() function
string public constant value = "myValue2";

Constant and Immutable State Variables


State variables can be declared as constant or immutable. In both cases, the variables cannot be modified after
the contract has been constructed. For constant variables, the value has to be fixed at compile-time, while
for immutable, it can still be assigned at construction time.

Compared to regular state variables, the gas costs of constant and immutable variables are much lower
• Design of the SimpleStorage.sol

Exercise 3:
SimpleStorage.sol

storedData state transitions


In the design of SimpleStorage contract, you notice that
there is no explicit constructor. But a constructor is
automatically by default created for the smart
contract.
Based on design of SimpleStorage contract, CODE the
smart contract
From this exercise, the order of which function should be called is
important which will affected the data in state variable, storedData.
Simple Storage Demo

copy the Smart Contract address and put it in the local contract address. Then at that address, you are creating one
more smart contract. That's how the smart contracts all over the world are in consistent state.
Send the ether from one account to another
account

1 Ether = 1,000,000,000,000,000,000 Wei (10 18


)

You might also like