Blockchain #1: Basic of Ethereum on Blockchain Technology

Arista Indrajaya
8 min readMay 10, 2020
*This is an image from ethereum.org/assets

Ethereum one of excited Blockchain Framework

#What is Ethereum?

Ethereum is one of the technologies used for developing blockchain technology. Ethereum is also can be called a Network, the network means that Ethereum has a network that can be used to send money or stored data. But in this tutorial, we will learn about some basic Ethereum networks that called Local, test and Main network. On Ethereum network there are many nodes that interact with each other, and the nodes can be called a Machine or instance. As I said before that blockchain on this tutorial article (link) that blockchain is a database that stored a record of every transaction that has even taken place or happening before. Everyone who enters this network can run a node that contains all of the copy of the blockchain transaction data that build on Ethereum network. Transactions are not only about money, but any object transaction can be stored in the blockchain.

#What suppose I do with Ethereum?

Interacting With Ethereum
There are two roles that interact with Ethereum. First, is a developer and the second is a user. Developers, we know a people/person who builds this blockchain on Ethereum network. And user by mean is a people/person who uses this blockchain on Ethereum network for their daily needs such as transfer money, stored data, stored to-do list activity, or using for the election process. And how they can interact on Ethereum?. For developers they usually use Web3 it can be described like a portal that can make our window interact with Ethereum network (For the further description you can see this link). For customers, they usually use Metamask. But the developers also build some interactive client apps that can make the user interact with Ethereum networks without Metamask.

Metamask Setup
For the previous explanation, we discuss Metamask. Let say that Metamask is a crypto wallet & gateway to blockchain apps. And this how to set up Metamask so it can be used in our browser.
Go-to your browser extension and search Metamask or you can use this link (for Chrome or Firefox).
and Setting Up your account

There are important things you should pay attention to the installation process of Metamask. You should save Mnemonic Phrase that provides when installation process. As shown below

And this is the final window that you will get if you success to add Metamask application on your browser

Ethereum Accounts
An account is a small object of Ethereum that has some components that called by account states such as nonce, balance, storageRoot and codeHash. That describes like this:
Nonce: If the account is an externally owned account, this number represents the number of transactions sent from the account’s address. If the account is a contract account, the nonce is the number of contracts created by the account.
Balance: The number of Wei owned by this address. There are 1e+18 Wei per Ether.
storageRoot: A 256-bit hash of the root node of a Merkle Patricia tree that encodes the storage contents of the account (a mapping between 256-bit integer values), encoded into the trie as a mapping from the Keccak 256-bit hash of the 256-bit integer keys to the RLP-encoded 256-bit integer values. This tree encodes the hash of the storage contents of this account and is empty by default.
codeHash: The hash of the EVM (Ethereum Virtual Machine) code of this account — this is the code that gets executed should this address receive a message call; it is immutable and thus, unlike all other fields, cannot be changed after construction. All such code fragments are contained in the state database under their corresponding hashes for later retrieval. For contract accounts, this is the code that gets hashed and stored as the codeHash. For externally owned accounts, the codeHash field is the hash of the empty string.
This explanation refers to the Ethereum yellow paper here for more details.

And Ethereum accounts has two types, that is: First, Externally Owned Accounts (User accounts is controlled by private keys. Second is Contracts Accounts (controlled by code). This is my simple definition of Ethereum accounts, you can see a full of documentation in here.

Ethereum Smart Contracts
Ethereum Smart Contracts is an application that runs on the Ethereum Virtual Machine. And it is decentralized by position or usage and not focus on the one machine, where the computing power is provided by Ethereum nodes. And nodes that providing computing power are paid for that resource in Ether tokens. Smart Contracts can be used for many different things. And it is usually be used to store information on the Ethereum blockchain. Another simply definition Smart Contract is like an account but its controlled by some amount of code (or you can say the smart contract is an account controlled by code and developer create the code, this code instruct the smart contract how to behave).

Solidity Programming Language
Solidity is strongly typed just like JavaScript and is invented specifically for authoring Smart Contracts and so it has many features inside the language to make the execution of these contracts much easier. Solidity is written in .sol files that compatible with any standard code editor.

Contract Structure
This an example that I take from solidity documentation. A simple Smart Contract basically consists of this.

Returns keyword down on the get() function, returns is used to specify the type of return value that we can expect to see back from a function. Returns are only ever going to be used on functions that are marked as the view or constant.

Functions Declaration
In this section we will describe Common function types:
Can only use one per function :
-
public: anyone with an account can call this function
- private: only this contract can call this function
They mean the same thing:
-
view: this function returns data and does not modify the contract’s data
- constant: this functions returns data and does not modify the contracts’ data
Other
Pure: function will not modify or even read the contract’s data
payable: when someone calls this function they might send ether along, some outside entity attempts to call a function on a contract payable means that we might attempt to call it and send money to the contract at the same time.
Return it will return the initial conditions.

#Try Ethereum

Testing with Remix
Remix is helping us to automatically compiled by the solidity compiler, and that’s going to compile it to bytecode that will then be deployed to an in-browser fake Ethereum network and that will give use instance of our inbox contract. Remix is not just a smart contract editor, it also hosts a miniature tiny little fake Ethereum network that we can use to simulate deploying and interacting with our contract.

Behind the Scenes of Deployment
What happened when we selected our Simple Storage contract right here typed in some entry argument and then click the deploy/create button. when we create a new contract a very similar process occurs. So creating a contract is very similar to the transfer of money between two different parties. So just as before whenever we want to send money from one person to another we are going to create.
External account to create contract transactions
Nonce: how many times the sender has sent a transaction.
To: left as blank. It that means we are going to attempt to create a new contract. And in fact, we could even recall that we use the web3 library to interact with the network directly programmatically.
Data: compiled bytecode of the contract. So this is where the code that comes out of the solidity compiler is sent in and stored on the network.
Value: the amount of Wei to send to the target address.
gasPrice: the amount of Wei the sender is willing to pay per unit gas to get this transaction processed.
startGas/gasLimit: the unit of gas that this transaction can consume.
v/ r/ s properties: are derived from the sender’s private key and can be used to derive their public key.
We can both create a contract and send it some initial amount of money that it can play around with to do whatever it is our contract is trying to achieve.

#Measurement on Ethereum

Wei, Ether, Gas and Transactions
Costs take money, it will cost an ether to send a transaction to a function. And Wei is a small unit of ether or the smallest of unit measurement on ether. The gas system in Ethereum is meant to measure how much work we are executing with our code:
- gasPrive: the amount of Wei the sender is willing to pay per unit gas to get this transaction processed.
- startGas/ gasLimit: units of gas that this transaction can consume
Let’s Examine this function by determine transaction to call function ‘doMath’ gasPrice is 300wei and gasLimit is 10.

Gas needed for all of the operations needs 14 gas

for the price for detail function you can see on gas prices yellow paper.

#Other

Mnemonic Phrases
The concept of a 12 word pneumonic, a 12 word Mnemonic allows us to automatically generate a series of different accounts with a public key, a private key and an address. 12 word of mnemonic is a series of 12 random words like the ones that you see on Metamask.
The idea behind these new this 12 mnemonic right here is what we can feed these 12 words into a mnemonic algorithm(BIP39 mnemonic algorithm), when we feed them into this algorithm it will spit out a series of different accounts each of which has their own public key, private key and address. So rather than having to memorize all of these three or more different keys that Ethereum gave to us, you can only memorize the 12-word mnemonic.

--

--