Ethereum Private Blockchain

Ethereum is a programmable blockchain that allows users to create their own operations. This Refcard highlights fundamental information on Ethereum Blockchain and demonstrates the steps to get a private blockchain up and running. By the end, you will be able to set up two running nodes on one local machine.

Introduction

Background

A blockchain is a distributed computing architecture where every node runs in a peer-to-peer topology, where each node executes and records the same transactions. These transactions are grouped into blocks. Each block contains a one-way hash value. Each new block is verified independently by peer nodes and added to the chain when a consensus is reached. These blocks are linked to their predecessor blocks by the unique hash values, forming a chain. In this way, the blockchain’s distributed dataset (a.k.a. distributed ledger) is kept in consensus across all nodes in the network. Individual user interactions (transactions) with the ledger are append-only, immutable, and secured by strong cryptography. Nodes in the network, in particular the public network, that maintain and verify the transactions (a.k.a. mining) are incentivized by mathematically enforced economic incentives coded into the protocol. All mining nodes will eventually have the same dataset throughout.

Ethereum is an open-source blockchain platform that allows anyone to build and use decentralized applications running on blockchain technology. Ethereum is a programmable blockchain – it allows users to create their own operations. These operations, coded as Smart Contracts, are deployed and executed by the Ethereum Virtual Machine (EVM) running inside every node.

The public blockchain is open to anyone who wants to deploy smart contracts and have their executions performed by public mining nodes. Bitcoin is one of the largest public blockchain networks today. As such, there is limited privacy in the public blockchain. Mining nodes in the public blockchain requires a substantial amount of computational power to maintain the distributed ledger at a large scale. In the Ethereum public blockchain, smart contract codes can be viewed openly.

A private blockchain can be set up within the safety confines of a private network within an organization. Hence, nodes participating in transactions are authenticated and authorized machines within the organizational network.

The following text of this Refcard highlights fundamental information on the Ethereum Blockchain and the basic steps to get a private blockchain up and running. At the end of this Refcard, you should be able to set up two running nodes on one local machine.

Accounts and Contracts

There are 2 types of accounts in Ethereum:

  • External Account, which stores ETH balance – This contains the address of the User that was created using the Web3.js API, e,g, personal.newAccount(…). These accounts are used for executing smart contract transactions. ETH is your incentive received for using your account to mine transactions. The address of the account is the public key, and the password of the account is the private key.

A public example of an External account that stores ETH can be found here:

  • Contract Account, which stores ETH balance and has codes – This contains the address of an instance of Smart Contract codes. Instance(s) of smart contracts can be created programmatically or via Browser-Solidity using Web3 APIs.

A public example of a contract account that has a smart contract can be found here:

Smart Contract Creation

Smart Contracts contain the program codes to be executed, and are analogous to a C++, C#, or Java class. It contains:

  • States variables
  • Functions
  • Events

Smart Contracts are compiled to bytecodes. These bytecodes are deployed as instances of Smart Contracts in the Ethereum Virtual Machine (EVM).

Image title

An instance of a Smart Contract is created by an External Account (or by the default account of the executing node):

  • The creation process triggers a Transaction.
  • The Transaction has to be mined to take effect. For example, later sections will show that you can check pending transactions using the API eth.pendingTransactions().
  • Mining is “competitively performed” by peer nodes. For example, later sections will show this by using the API miner.start().
  • On successful mining by a node, a new Block is created, which contains the Transaction and Contract Address.
  • The mining node will broadcast the new Block to peer nodes.
  • The new block will be validated and verified by peer nodes to be become an official block in their local blockchains.
  • The new instance of the Smart Contract contains a unique address. This address must be saved, recorded, or registered. It will be retrieved for subsequent “contract execution.”

Smart Contract Execution

A Smart Contract contains functions that can be executed by an External Account or a Decentralized Application (DAPP). In the case of a DAPP, the executing node would have a default External Account.

Image title
  • To execute a function defined in the Smart Contract, the DAPP retrieves a unique instance of the Smart Contract by its address.

E.g.

> var address = "0xc7caf784fae5840bdc893b03b7391fce6efb6190"
> var myContract = eth.contract(abi).at(address)
  • Functions that change the state(s) of a contract will trigger a Transaction.

E.g.

> myContract.setTimeIn(“08:45”)
  • The Transaction has to be mined to take effect. For example, later sections will show that you can check pending transactions using the API eth.pendingTransactions().
  • Mining is “competitively performed” by peer nodes. For example, later sections will show this by using the API miner.start().
  • On successful mining by a node, a new Block is created, which contains the Transaction.
  • The mining node broadcasts the new Block to peer nodes.
  • The new block will be validated, verified, and its transaction executed locally by peer nodes to be become an official block in their local blockchains.

[ad_2]

Source link