Basics you need to know about Solidity and how it works. Learn the simple way of building a smart contract in Solidity. Tools that can be used with Solidity.
2. @ennytwit
- Senior Consultant @ Andela
- Php, C#, Python, Ruby & Solidity
- Drama Director
- Anime Lover
- BasketBaller
- Football Analyst
3. Contents
What can you do today with Ethereum
Understanding Dapp
Web Applications vs Dapp
Ethereum Nodes
Ether and its denominations
Using MetaMask
Smart Contract - Writing Code with Remix
Smart Contract - Same Contract with Editor
5. What you can do today with Ethereum and Dapps?
- The Ethereum Blockchain can be used as a public blockchain and
- A protocol for the creation of many blockchains (Private blockchain)
What can be done in both?
- Send and Receive Ether
- Write Smart Contracts
- Create provable fair applications
- Launch your own token based on ether
- The promise of Decentralized Databases
6. Understanding Dapp
What is a Dapp?
It is a Decentralized application
- It is a peer to peer solution
- Data is shared
- Code is shared
8. Ethereum Nodes
Kenya
Ethereum Virtual Machines: Mining Nodes:
Think of EVM as the execution runtime for
Ethereum network. EVM’s main function is to
provide a runtime where all smart contracts
code are executed.
EVM are the execution component in
Ethereum. The purpose of EVM is to execute
the code in smart contract line by line.
Mining Nodes refers the nodes that belong to Miners.
These nodes are part of the same network where EVM is
hosted. At some point of time, the miners would create a
new Block, collect all transaction from transaction pool and
adds them to the newly created block. Finally, this Block is
added to the chain
10. Types of Transactions in Ethereum
1. Transfer of Ether from one account to another
2. Deployment of Smart contract .
3. Using or invoking a function within a contract
Each of the above requires an amount of Ether to execute
11. Components of a Transaction in Ethereum
Component Description
From It denotes the account originating the transaction
To It denotes the account receiving the ethers or benefits of the transaction
Value The value of the ether being transferred or executed
BlockHash The Hash of the block this transaction belongs to
Block Number Block the transaction belongs to
GasPrice The price per gas the sender is willing to pay in Wei
Gas Amount of gas supplied by the sender which is executing this transaction
Hash Hash of the transaction
Nonce How many times the sender has sent a transactions prior to this one
TransactionIndex Serial Number of Transaction in block
V
This is the digital signature and signing of the transaction in cryptographic pieces of dataR
S
12. Components of a Block in Ethereum
Component Description
Difficulty It determines the complexity of the puzzle/challenge given to the miners for this
block
GasLimit It determines the maximum gas allowed.
GasUsed The actual gas used for this block for executing all transactions in it.
Miner The account identifier of miner also known as coinbase or Etherbase
Number The sequential number of this block on the chain
ParentHash The parents blocks hash
ReceiptsRoot, StateRoot and
transactionRoot
Refers to Merkel trees discussed during mining process.
Hash Hash of the transaction
Nonce How many times the sender has sent a transactions prior to this one
Transactions The array of transactions that are part of this block.
TotalDifficulty The total difficulty of the chain until this block
13. The Ether
Ether is the currency of Ethereum.
Every activity on Ethereum that modifies its state costs Ether as fee and
miners who are successful in generating and writing a block in chain are also
rewards Ether
15. Gas Costs
Ether is the currency of Ethereum.
Every activity on Ethereum that modifies its state costs Ether as fee and
miners who are successful in generating and writing a block in chain are also
rewards Ether
17. Writing Smart Contracts with Solidity
Versioning : Every smart contract in Solidity is tied to a version and must run
on the version to work effectively.
pragma solidity ^ 0.4.0;
contract Conditional {
uint refVal = 10;
uint limit = 20;
function isGreaterEqualUnderLimit(uint testVal) view public returns(bool) {
if (testVal >= refVal
&& testVal < limit) {
return true;
}
}
}
18. How smart contracts are deployed
ABI (Application Binary Interface): This is an interface consisting of all external
and public function declarations along with their parameters and return types.
All smart contracts are compiled into two components:
ByteCode : represents the contract and is deployed in Ethereum ecosystem.
An easy simple tool to compile code is REMIX. https://remix.ethereum.org
21. Basic Solidity Types
Basic Types
Name Description Examples
string Sequence of characters [Hi there] [I am here!!!]
bool Boolean Value true or false
int Integer, positive or negative. Has no decimal 0 -3000 59158
uint
Unsigned’ integer, positive integer. Has no
decimal
0 3000 80158
fixed/ufixed
Fixed’ point number. Number with a decimal
after it
24.56. -54.678 3.14
Address Has methods tied to it for sending money 0x18bae199c8dbae199c8d
22. Function Types
Common Function Types
public Anyone can call this function
private Only this contract can call this function
view
This function returns data and does not modify the
contracts data
constant
This function returns data and does not modify the
contract’s data
pure
This function will not modify or even read the contracts
data
payable
When this function is called some amount of ether will be
‘charged’
23. Processing Contract Functions
Process Tips
‘Calling’ a Function Sending a Transaction to a Function
Cannot modify contract’s data Can modify a contract’s data
Can return data Returns the transaction hast
Runs instantly Takes Time to execute
Free to do or use Cost Money/Gas
24. Tools to use for Solidity Development
Node
Truffle
Ganache
MetaMask (extension for chrome)
IDEs e.g Atom, VSCode etc
Syntax Highlighting for your IDE
Remix
25. Remix
What is Remix?
Remix is an online solidity IDE that is used for writing and testing smart
contracts
http://remix.ethereum.org
https://remix.readthedocs.io/en/latest/
Location:
Documentation:
28. Syntax highlighting for IDEs
Atom - https://atom.io/packages/language-ethereum
Open the package installation manager in atom and search for 'language-ethereum'.
After installing the package, you might have to manually change the highlighter in the .sol file. Look for the
selector at the bottom right of your editor window.
Sublime - https://packagecontrol.io/packages/Ethereum
VSCode - https://github.com/juanfranblanco/vscode-solidity
Webstorm - https://plugins.jetbrains.com/plugin/9475-intellij-solidity
VIM - https://github.com/tomlion/vim-solidity