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

Ethereum wallet and solidity tutorial

The document is a tutorial on Ethereum wallet setup and Solidity programming, covering topics such as Ethereum's decentralized nature, smart contracts, and wallet security. It explains key features of Ethereum, the importance of wallets, and provides guidelines for creating and managing Ethereum wallets. Additionally, it introduces Solidity, its structure, and the process of developing smart contracts using the Remix framework.

Uploaded by

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

Ethereum wallet and solidity tutorial

The document is a tutorial on Ethereum wallet setup and Solidity programming, covering topics such as Ethereum's decentralized nature, smart contracts, and wallet security. It explains key features of Ethereum, the importance of wallets, and provides guidelines for creating and managing Ethereum wallets. Additionally, it introduces Solidity, its structure, and the process of developing smart contracts using the Remix framework.

Uploaded by

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

INFORMATION TECHNOLOGY UNIVERSITY

Ethereum Wallet Setup and Solidity Tutorial

Blockchain
Instructor: Dr Umar Janjua BS/MS fall 2024
Topics to be Covered

❏ Introduction to ethereum
❏ Ethereum Wallet
❏ Create Ethereum Wallet
❏ Overview of etherscan.io
❏ Smart Contracts
❏ Introduction to solidity
❏ Run First Smarct in Solidity
Introduction to Ethereum

Ethereum is a decentralized, open-source blockchain


platform that enables the development of decentralized
applications DApps and smart contracts. It was
proposed by Vitalik Buterin in 2013 and launched in 2015.
Unlike Bitcoin, Ethereum is not just a digital currency but
also a platform for building decentralized applications.
Key Features of Ethereum

Decentralization: Ethereum operates on a decentralized


network of computers, ensuring that no single entity has
control over the platform.

● Smart Contracts: Ethereum's key feature is its


ability to execute smart contracts, which are
self-executing contracts with the terms of the
agreement directly written into the code.
● Turing-Completeness: Ethereum's programming
language, Solidity, allows developers to build
complex applications with a wide range of
functionalities.
● Interoperability: Ethereum can interact with other
blockchains through interoperability protocols like
Polkadot and Cosmos.
Smart Contracts and
Decentralized Applications
(DApps)
Smart contracts are self-executing contracts with the
terms of the agreement directly written into the code.
They automatically execute transactions and enforce the
agreed-upon rules without the need for intermediaries.
DApps, on the other hand, are applications that run on a
decentralized network, utilizing smart contracts for their
functionality. They offer transparency, security, and
autonomy.
Ethereum Virtual Machine
(EVM) and Consensus
Mechanisms
The Ethereum Virtual Machine EVM) is a runtime
environment that executes smart contracts on the
Ethereum network. It enables developers to write and
deploy smart contracts using various programming
languages. Ethereum currently uses a consensus
mechanism called Proof of Stake PoS) called Ethereum
2.0, which aims to improve scalability and reduce energy
consumption.
Ethereum Tokens and Initial
Coin Offerings (ICOs)
Ethereum allows the creation of tokens on its platform,
which are used for various purposes, including
crowdfunding, voting rights, and access to specific
services within DApps. Initial Coin Offerings ICOs
became popular on Ethereum, where startups raise
funds by selling tokens to investors in exchange for
cryptocurrencies like Ether ETH.

Nodes can be run by anyone on ethereum, although to


participate in securing the network you have to stake
ETH. Anyone with 32 ETH can do this without needing
permission.
Ethereum Gas
Ethereum gas is a unit of measurement for the computational effort required to execute transactions on the ethereum
blockchain.
ADD …. 3
Gas is required for every transaction and smart MUL …. 5
contract execution on the Ethereum network, and is SUB …. 3
used to pay for the computational resources DIV …. 5
consumed by the nodes that validate and execute the MOD …. 5
transactions. The amount of gas required for a ADDMOD . 8
transaction or smart contract execution is dependent MULMOD . 8
on the complexity of the operation.

Gas prices in Ethereum are dynamic and determined


by the market demand. When the demand for gas is
high, the gas price increases, and when demand is
low, the gas price decreases
Ethereum Compatible Blockchain
Some of the blockchain networks that use the EVM and are able to interact with the ethereum ecosystem through smart contracts.
Use Cases and Applications of
Ethereum
Decentralized Finance DeFi Ethereum powers various
DeFi applications such as lending platforms,
decentralized exchanges, and stablecoins.

● Supply Chain Management: Ethereum's


transparency and immutability make it suitable for
tracking and verifying the authenticity of
products in supply chains.
● Gaming and Collectibles: Ethereum enables the
creation and trading of non-fungible tokens
(NFTs) used in gaming, digital art, and
collectibles.
● Identity and Voting Systems: Ethereum can be
used to create secure and decentralized identity
systems and voting platforms.
Challenges and Future
Developments in Ethereum
While Ethereum has made significant progress, it still
faces challenges such as scalability, high gas fees, and
energy consumption. To address these challenges,
Ethereum is transitioning to Ethereum 2.0, which aims to
improve scalability through techniques like sharding and
a move to Proof of Stake PoS. The upgrade will
enhance the platform's performance, security, and
sustainability.
Introduction to Ethereum Wallets
Ethereum wallets play a crucial role in securely storing and managing Ethereum assets. They are digital tools that
allow users to interact with the Ethereum blockchain.

Understanding the Concept of Wallets in the Context of Ethereum

Ethereum wallets are not physical wallets, but rather software applications that enable users to store, send, and
receive Ethereum. They consist of a public address, which is similar to a bank account number, and a private key,
which is like a password that grants access to the wallet and the associated Ethereum assets.

Importance of Wallets in Securely Storing and Managing Ethereum Assets

Wallets are vital for securely storing and managing Ethereum assets. They provide a secure environment for holding
private keys and facilitate the sending and receiving of Ethereum transactions. Without a wallet, it would be
challenging to access, manage, and utilize Ethereum assets effectively.
Types of Ethereum Wallets

Overview of Wallet Types Pros and Cons of Wallets

Software wallets offer convenience


Ethereum wallets can be broadly but can be susceptible to malware.
Hot vs Cold Wallets Hardware wallets provide excellent
categorized into four types:
software wallets, hardware Hot wallets are connected to the security but may be less user-friendly.
wallets, paper wallets, and web internet for easy access, suitable Paper wallets allow offline storage but
wallets. Each has its advantages for regular transactions. In need careful handling, while web
and considerations, catering to contrast, cold wallets are offline, wallets ensure easy access but may
different user preferences. providing an extra security layer pose security risks.
by keeping private keys offline.
How to Generate an Ethereum Wallet
Choose a reputable wallet provider or software.
Create a new wallet address and private key.
Secure and back up the wallet by following best practices.
Wallet Security Best Practices

Importance of Strong Passwords and


Offline Storage and Phishing Caution
Authentication

Ensuring the security of an Ethereum wallet is Consider using offline storage options, like
paramount. Using a strong password and hardware wallets, to securely store private keys.
enabling two-factor authentication adds an extra Also, be cautious of phishing attacks and malware
layer of security to the wallet. Strong passwords that can compromise wallet security; verifying the
should be unique, complex, and not easily authenticity of websites is essential.
guessable.
Managing and Using an Ethereum Wallet

Key Features of Ethereum Transaction Management Wallet Balances and DApp


Wallets Integration

Ethereum wallets provide features Users can send and receive Users can check wallet balances
such as sending and receiving Ethereum transactions by and transaction history easily
Ethereum transactions, managing entering the recipient's wallet within the wallet interface. Some
multiple wallet addresses, and address, specifying the amount, wallets also allow DApp
interacting with decentralized and confirming the transaction, integration, enabling interaction
applications (DApps) on the which is vital for financial activities with various decentralized
Ethereum blockchain. on the Ethereum network. applications built on the
Ethereum blockchain.
Conclusion and Tips for Ethereum Wallet Usage

Significance of Ethereum Wallets In conclusion, Ethereum wallets are crucial for securely storing and
managing Ethereum assets. They provide a means to securely store, send,
and receive Ethereum assets, essential for interacting with the Ethereum
blockchain.

Guidelines for Safe Management To ensure safety, choose reputable wallet providers, set strong passwords,
enable two-factor authentication, consider offline storage options, and be
cautious of phishing attacks and malware. Regularly update wallet
software and keep backups.
Understanding Smart Contracts
Smart contracts are self-executing contracts with the
terms of the agreement directly written into code. They
automatically execute when predefined conditions are
met, without the need for intermediaries. Smart contracts
are deployed on the blockchain, ensuring transparency,
immutability, and security.

Real world examples

Stable coins NFTs


DEXs

Decentralized
Token
Applications
Standards
Smart Contracts Development and Deployment

1 2 3 4 5 6

Design Code Writing Compilation Deployment Testing Maintenance

Design the contract Implementing the Solidity code compiled Compiled code get Performing various tests Monitoring performance
including defining its functions events, and into bytecode that can be deployed on the on the contract including and detecting abnormal
structure, state, conditions defined in the deployed on the blockchain and make it unit tests, integration usage
variables, functions, and design step blockchain available to the network tests, security tests.
events.
Introduction to Solidity
Solidity is a high level, contract-oriented programming language that is used for writing smart contracts on the
ethereum-compatible blockchain.

● Solidity developed specifically for the ethereum platform and is influenced by C++, python and JavaScript.
● Solidity is designed to provide a simple and secure way to create self-executing contracts that enforce the
rules and conditions of an agreement between parties.
● Solidity contracts are executed on the Ethereum Virtual Machine, which is built into Ethereum blockchain and
allow developers to create decentralized applications and automate the transfer of digital assets based on the
conditions encoded in the contract.
● Supports features such as multiple inheritance, user-defined types, events, modifiers which makes it possible
to write complex, feature-rich smart contracts.
Introduction to Remix Framework for Solidity

Benefits of using the Remix Framework Accessing the Remix Framework online

The Remix Framework is a powerful tool for Solidity


development. It offers several benefits: The Remix Framework can be accessed online
1. User-friendly interface: Remix provides a through the Remix IDE, which is available at
user-friendly interface that simplifies the process remix.ethereum.org. It is a web-based tool that
of writing, deploying, and interacting with Solidity eliminates the need for local installations and
contracts. provides a seamless development experience.
2. Integrated development environment: Remix
offers an integrated development environment
(IDE)
3. Built-in compiler: Remix comes with a built-in
Solidity compiler, allowing developers to compile
their contracts with ease.
4. Debugging capabilities: Remix provides
debugging capabilities, enabling developers to
identify and fix issues in their Solidity contracts.
Inheritance and Libraries in Solidity

Inheritance in Solidity Libraries in Solidity

Inheritance in Solidity allows for code reuse and Additionally, Solidity supports libraries, which are
modularity. Contracts can inherit properties and collections of reusable code that can be deployed
functions from other contracts, creating a independently or used by other contracts. Libraries
hierarchical structure. This promotes code provide a way to share common functionality
organization and reduces redundancy. across multiple contracts, improving code efficiency
and reducing gas costs.
Layout and Structure Solidity Smart Contract
● Contracts in solidity are similar to classes in object-oriented languages.
● Each Contract can contain declarations of
○ Pragma directives
○ State Variables
○ Functions
○ Function Modifiers
○ Events
○ Errors
○ Struct
○ Enum
Contract
● A smart contract is a computer program that automatically executes the terms of a contract when certain
conditions are met.
● Every contract defines its own type. You can implicitly convert contracts to contracts they inherit from.
● Contracts can be explicitly converted to and from the address type.
● If you declare a local variable of contract type (MyContract c), you can call functions on that contract. Take
care to assign it from somewhere that is the same contract type.
● Contracts do not support any operators.
● The members of contract types are the external functions of the contract including any state variables
marked as public
Example of Smart Contract
Pragma
● Used to specify the compiler version for specific solidty file
● You need to add pragma in your all files as its specific to a file
● The pragma version is used as follows:

pragma solidity ^0.5.2;


pragma solidity >=0.4.22 <0.9.0;
State Variables in Solidity
State variables in Solidity are variables that are
permanently stored in the contract's storage. They
represent the contract's state and can be accessed and
modified by functions within the contract. State variables
are declared at the contract level and can be of various
types, such as integers, booleans, strings, and
custom-defined data types. Understanding state variables
is crucial for managing and persisting data within a Solidity
smart contract.
State Variable Types
● State Variables:
○ Variables whose values are permanently stored in a contract storage.
● Local Variables:
○ Variables whose values are present till function is executing.
● Global Variables:
○ Used globally and give information about transection and Blockchain properties
○ e.g gasleft() returns the amount of gas left

● Variables whose values are permanently stored in contract storage.

pragma solidity >=0.4.0 <0.9.0;


contract SimpleStorage {
uint storedData ; // State variable
}
State Variable Visibility

● Public: Can be accessed by the contract and also other contracts.

● Internal: Can only be accessed within the contract and in its subclasses.

● Private: Variable can only be accessed within the contract its defined.
Value Types

Booleans Integers
bool: The possible values are constants true and false. Integers: int / uint: Signed and unsigned integers of various
Operators: sizes.

● ! (logical negation) Operators:


● && (logical conjunction, “and”) ● Comparisons: <=, <, ==, !=, >=, > (evaluate to bool)
● || (logical disjunction, “or”) ● Bit operators: &, |, ^ (bitwise exclusive or), ~ (bitwise
● == (equality) negation)
● != (inequality) ● Shift operators: << (left shift), >> (right shift)
● Arithmetic operators: +, -, unary - (only for signed
integers), *, /, % (modulo),
** (exponentiation)
Value Types

Address
The address type comes in two flavours, which are largely identical:

● address: Holds a 20 byte value (size of an Ethereum address).

● address payable: Same as address, but with the additional members


transfer and send.

address payable x = payable(0x123);


address myAddress = address(this);
if (x.balance < 10 && myAddress.balance >= 10)
x.transfer( 10);
Constructor in Solidity
In Solidity, a constructor is a special function that is
executed only once when the contract is deployed. It is
used to initialize the state variables of the contract and
perform any necessary setup. The constructor has the
same name as the contract and does not have a return
type. Constructors can take parameters, allowing for
customization during contract deployment. Understanding
constructors is essential for initializing contracts and
preparing them for use in the Ethereum network.
Functions in Solidity
Functions in Solidity are blocks of code that perform
specific tasks and can be called by other contracts or
external accounts. They can have parameters and return
values, allowing for data manipulation and interaction
with the contract's state. Solidity supports various types of
functions, including view functions that do not modify
the state, pure functions that do not access the state,
and fallback functions that are executed when a contract
receives a plain Ether transaction without any data.
Understanding functions is vital for implementing the logic
and behavior of Solidity smart contracts.
Functions Visibility
● External: Can be accessed from other contracts using the transections.

● Public: Part of the contract interface and can be either called internally or via message calls.

● Internal: Internal functions can only be accessed from within the current contract or
contracts deriving from it.

● Private: Private functions are like internal ones but they are not visible in
derived contracts.
Variables in Solidity
Variables in Solidity are used to store and manipulate data
within a contract. Solidity supports different types of
variables, including integers, booleans, addresses, strings,
arrays, and more. Variables can be declared at the
contract level or within functions, and their scope
determines where they can be accessed. Understanding
variables and their types is essential for managing data
and implementing the desired functionality in Solidity
smart contracts.
Data Types in Solidity
Solidity offers various data types to handle different kinds
of data in smart contracts. These data types include
integers, booleans, addresses, strings, arrays, mappings,
and more. Each data type has its specific use cases and
properties, enabling developers to manipulate and store
data efficiently. Understanding the different data types in
Solidity is crucial for designing smart contracts that can
handle and process data accurately and securely.
Mapping and Arrays in Solidity

Mapping in Solidity Arrays in Solidity

Mapping: A mapping is a key-value store that Arrays: Arrays are ordered collections of elements
associates a value with a unique key, allowing for that can be of the same or different data types.
efficient lookup and retrieval of values. Mappings They allow for storing and accessing multiple values
are commonly used to represent relationships sequentially and can be dynamically or fixed-sized.
between different entities in a smart contract.
Writing your First Solidity Contract

Setting up the Remix Writing and compiling your


environment Understanding the first Solidity contract
To start writing Solidity contracts
structure of a Solidity Using the Remix IDE, you can
using Remix, follow these steps: contract write and compile your first
Access the Remix IDE at Solidity contract. Start by defining
remix.ethereum.org. A Solidity contract consists of the contract name, state
Create a new file or open an several key components: Pragma variables, functions, and any
existing one. statement, Contract declaration, additional components required.
Choose the appropriate Solidity State variables, Functions, Once the contract is written, use
version for your contract. Modifiers, Events: the built-in compiler in Remix to
compile the contract and check
for any errors.
Running your First Solidity Contract

Deploying the contract on the Remix Interacting with the contract through
environment Remix
To run a Solidity contract, you need to deploy it Once the contract is deployed, you can interact
on the Remix environment. Remix provides a with it using Remix. Remix provides a user
deployment feature that allows you to choose the interface for interacting with the functions and
deployment method, such as using JavaScript VM, state variables of the deployed contract. You can
Injected Web3, or connecting to a local blockchain input values, trigger functions, and observe the
network. Select the appropriate deployment changes in the contract's state.
method and follow the instructions provided by
Remix.

You might also like