Translated from German to English - www.onlinedoctranslator.com

Smart contracts for the Ethereum

+ Cryptocurrencies

+

TechDocs

blockchain

+

Seek

Blockchain refers to a continuously expandable list of data records, which are linked to one another by means of cryptographic processes, so that the chain of data records is unchangeable and forgery-proof. New transactions are validated and packed into blocks, and the blocks are appended to the blockchain after going through a consensus algorithm and sent to all other blockchain servers.

Ethereum is based on a public blockchain, which is used in a decentralized peer-to-peer network on many Ethereum servers as DLT is operated. Ethere um includes the Cryptocurrency Ether and also enables " Smart contracts ". This allows contracts to be programmed, which are then executed and checked electronically. For this purpose, scripts are created (mostly in the programming language Solidity ) and executed in the Ethereum Virtual Machine (EVM).

This opens up very diverse possibilities, for example many are based ICOs thereon. However, special care must be taken when programming smart contracts: those who are programmed

Security gaps can have fatal consequences, as with " The DAO Hack", which led to the Ethereum hard fork" Ethereum Classic ".

Basic explanations can be found under: Cryptocurrencies, Bitcoin, Ethereum, Blockchain . Some simple programming examples for smart contracts are shown below.

contents

1. Basic installations: Geth, Solc, private test Ethereum blockchain

2. First smart contract: hello world demo

3. Mini token smart contract: MeinToken demo

4th Remix Online Solidity Compiler as a graphical development environment (GUI-IDE)

5. Perform a MeinToken transfer with the GUI tool Mist

6th DApp website for the smart contract with Node.js 7th Transfer of Ether with Web3j and Java

8th. Transfer of your own smart contract tokens with Web3j and Java

9. DApp website for the smart contract with Java

10. Public Rinkeby Test Ethereum blockchain instead of private blockchain

11. Deploy smart contract in the public Rinkeby blockchain

12th DApp website for the smart contract in the Rinkeby blockchain

13th Truffle for easy development and quick testing 14th Embark for easy development and quick testing

15th DApp website for the smart contract with both Truffle and Embark

16. Use of the Oraclize service for external information queries

17th Analysis of the blocks and transactions

18th Solidity plug-in for JetBrains IntelliJ IDEA

19th documentary

Basic installations: Geth, Solc, private test Ethereum blockchain

This demo shows:

-As "geth"(Go Ethereum) will be installed.

-As "solc"(Solidity Compiler) will be installed.

-Like your own private Test Ethereum Blockchain is set up and started.

-As a Account created and Mining is started.

The following versions are used:

-geth 1.8.2

-solc 0.4.19

-web3 0.20.1

-Windows 10

The following text focuses on simplicity and good comprehensibility. For the time being, only command line tools are used. On graphical tools will further down received.

In this example, a private Ethereum blockchain that only exists on your own PC is set up. How a public Ethereum blockchain can be used will further down shown.

The commands are shown for Windows. When using Linux or Mac OS X, it is often sufficient to replace "\" with "/" in path specifications and ";" in PATH specifications. with ":" and with placeholders% MEINE_VARIABLE% by $ MEINE_VARIABLE.

Follow the steps outlined below.

1. Change to your preferred workspace directory (e.g. \

Mein Workspace) and execute the following commands:

cd \ MyWorkspace

mkdir EthereumDemo

cd EthereumDemo

mkdir solc

mkdir src

tree / F

2. Install solc ( Solidity Compiler): Download from https://github.com/ ethereum/solidity/releases the installation file suitable for your operating system, e.g. for Windows: solidity-windows.zip.

Under Windows, unzip this zip file in the directory:

\ MeinWorkspace \ EthereumDemo \ solc.

For other operating systems, proceed either analogously or as described under: In stalling the Solidity Compiler .

  1. Execute in the command line window:cd \ MeinWorkspace \ EthereumDemo solc \ solc.exe --version

solc \ solc.exe --help

Both commands must show plausible results.

4th Install geth (Go Ethereum):

Download

from https://geth.ethereum.org/downloads / a Geth version suitable for your operating system,

for example for Windows "Geth 1.8.2 for Windows".

Do not use Geth versions 1.8.0 and

1.8.1, because it means that the Web3j Issue 318 comes. For Windows you will receive the file "geth-windowsamd64-1.8.2-b8b9f7f4.exe". Run this file. The installation extends the Windows search PATH to include the Geth directory.

For other operating systems, proceed as described under: https:// www.e thereum.org/cli or https://git hub.com/ethereum/go

- ethereum / wiki / Building-Ethereum.

  1. Open a new command line window for configuration changes and PATH extensions to take effect. In it do:

cd \ MeinWorkspace \ EthereumDemo

geth version

geth help

Both commands must show plausible results.

You can also find a list of the command line options of geth under: Command line options.

6th Genesis block:

To start your own private test Ethereum blockchain, manual initialization of the first Genesis block is required. Create the JSON file in the src subdirectory:

genesis-block.json

{

"alloc": {},

"coinbase": "0x0000000000000000000000000000000000000000",

"config": {},

"difficulty": "0x4000",

"extraData": "0x4711",

"gasLimit": "0xffffffff",

"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",

"nonce": "0x0000000000000042",

"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",

"timestamp": "0x00"

}

When saving, make sure that the file must be saved with Unix line end characters and as an ASCII file without UTF-BOM.

You can find some notes on the Genesis block at: Creating The Genesis Block.

  1. Create the Genesis Block by running:cd \ MeinWorkspace \ EthereumDemo

geth -datadir "Private-Blockchain" init src /genesisblock.json

You will receive, among other things:

Successfully wrote genesis state

8th.Start of the own test Ethereum blockchain (without mining for the time being): Execute (in one line):

geth -networkid 77 --identity "MyDevChain"

You will receive, among other things:

Starting peer-to-peer node

HTTP endpoint opened: http://127.0.0.1:8545 Welcome

to the Geth JavaScript console!

And you get the Geth-JavaScript-Console, in which you can enter Geth-JavaScript commands.

9. Take a look at the documentation on the web3.eth commands: web3.eth

1.0 respectively. Web3 0.20.x JavaScript API . Query the

Web3.js version you are using:

web3.version.api

  1. Test whether accounts already exist. If the insertion of commands with Ctrl + V does not work, try the right mouse button, "Insert" and Return:

web3.eth.accounts

You will get an empty quantity:

[]

11.Create Account:

Create an account (think of a more difficult password and remember it well):

personal.newAccount ("My Ethereum Test Passphrase"

)

You will receive a 40-digit hex number as an account address, for example:

"0x2f94831a57a96041064d9d0c24583b12f807f2a5"

  1. Test again for existing accounts: web3.eth.accounts

For example, this time you will get:

["0x2f94831a57a96041064d9d0c24583b12f807f2a5"]

13th Query account balances:

Create the JavaScript file in the src subdirectory:

checkAllBalances.js

function checkAllBalances () {

web3.eth.getAccounts (function (err, accounts) {

accounts.forEach (function (id) {

web3.eth.getBalance (id, function (err, balance) {

console.log ("" + id + ": \ tbalance:" + web3.fromWei (balance, "ether")

+ "ether");

});

});

});

};

checkAllBalances ()

  1. Run in the Geth JavaScript Console:loadScript ('src / checkAllBalances.js')

You receive:

0x2f94831a57a96041064d9d0c24583b12f807f2a5:balance: 0 ether

15thStart mining manually:

Execute (do not execute the individual JavaScript commands too quickly one after the other):

miner.setEtherbase (web3.eth.accounts [0]) miner.start (1)

You get a never-ending output of mining commands:

Starting mining operation Commit

new mining work Successfully sealed

new block mined potential block

. . .

If mining does not start for you: Sometimes it happens that mining only starts after maybe 10 minutes.

Give the mining some time, about a minute. You will then find Ether on the account.

16. End the test Ethereum blockchain:exit

17th Start script:

Create the batch file in the EthereumDemo project directory start-test-

Ethereum-Blockchain.bat with the following content (in one line):

geth --networkid 77 --identity "MeineDevChain"

2 >> priv-geth.log

Note that this time mining is automatically activated with "--mine -- minerthreads 1", and with "2 >> priv-geth.log" the many outputs are redirected to a log file.

18thStart of our own test Ethereum blockchain including mining:Do:

cd \ MeinWorkspace \ EthereumDemo start-test-Ethereum-Blockchain.batFor example, you get:

Welcome to the Geth JavaScript console!

instance: Geth / MeineDevChain / v1.8.2-stable-b8b9f7f4 / windows-amd64 / go1.9 coinbase:

0x2f94831a57a96041064d9d0c24583b12f807f2a5

at block: 1448 (Mon, 22 Jan 2018 12:53:13 CET)

datadir: \ MeinWorkspace \ EthereumDemo \ Private-Blockchain

modules: admin: 1.0 debug: 1.0 eth: 1.0 miner: 1.0 net: 1.0 personal: 1.0 rpc: 1.0 txpool: 1.0 web3: 1.0

19.Run in the Geth JavaScript Console:loadScript ('src / checkAllBalances.js')

This time you will receive a positive amount, for example:

0x2f94831a57a96041064d9d0c24583b12f807f2a5:balance: 4711 ether

  1. Carry out further commands to get to know each other, for example:

admin.datadir

admin.nodeInfo

eth

eth.getBlock ("latest")

miner.getHashrate ()