Build your own Blockchain - Magelan Cybersecurity - E-Book

Build your own Blockchain E-Book

Magelan Cybersecurity

0,0

Beschreibung

In this book you will learn, even as an absolute beginner, how to build your own blockchain on your own computer and link it to a smart contract (trading bot).

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern
Kindle™-E-Readern
(für ausgewählte Pakete)

Seitenzahl: 73

Veröffentlichungsjahr: 2021

Das E-Book (TTS) können Sie hören im Abo „Legimi Premium” in Legimi-Apps auf:

Android
iOS
Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Build your own Blockchain

TitelseiteCopyright

Translated from German to English - www.onlinedoctranslator.com

Smart contracts for the Ethereum

+Cryptocurrencies

+

TechDocs

blockchain

+

Seek

Blockchainrefers 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.

Ethereumis based on a public blockchain, which is usedin adecentralized peer-to-peer network on many Ethereumservers asDLTis operated.Ethereumincludes theCryptocurrencyEther andalso enables "Smart contracts". This allows contractsto be programmed, whichare thenexecuted and checked electronically. For this purpose, scripts are created (mostly in the programming languageSolidity) and executed in the Ethereum Virtual Machine (EVM).

This opens up very diverse possibilities, for example many are basedICOsthereon.However,special care must be taken when programmingsmart contracts: those who are programmed

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

Basic explanations can be found under:Cryptocurrencies, Bitcoin,Ethereum, Blockchain. Some simple programming examples for smartcontracts 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.js7th 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 testing14th 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 willfurther downreceived.

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 willfurther downshown.

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 (SolidityCompiler):Downloadfromhttps://github.com/ ethereum/solidity/releasesthe installation file suitable for youroperating 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.

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

solc \ solc.exe --help

Both commands must show plausible results.

4thInstall geth (Go Ethereum):

Download

fromhttps://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 thatthe Web3jIssue318comes. 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.ethereum.org/cli or https://github.com/ethereum/go

- ethereum / wiki / Building-Ethereum.

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.

6thGenesis 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:CreatingTheGenesis Block.

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"

- datadir "Private-Blockchain" --nodiscover --rpc

- rpcapi "db, eth, net, web3, personal, txpool"

- rpccorsdomain "*" console

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.0respectively.Web3 0.20.x JavaScriptAPI. Query the

Web3.js version you are using:

web3.version.api

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"

Test again for existing accounts: web3.eth.accounts

For example, this time you will get:

["0x2f94831a57a96041064d9d0c24583b12f807f2a5"]

13thQuery 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 ()

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

17thStart 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"

- datadir "Private-Blockchain" --nodiscover --rpc

- rpcapi "db, eth, net, web3, personal, txpool"

- rpccorsdomain "*" --mine --minerthreads 1 console

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

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

admin.datadir

admin.nodeInfo

eth

eth.getBlock ("latest")

miner.getHashrate ()

personal.listAccounts

txpool.content

web3

See the explanations for theManagementcommands at.

21. End the test Ethereum blockchain:exit

22ndChecking the keystore file and the directory structure:Do:

to you \ MeinWorkspace \ EthereumDemo \ Private- Blockchain \ keystore

There is theKeystore file, for example:

UTC - 2018-01-22T09-50-58.520494400Z - 2f94831a57a96041064d9d0c24583b12f807f2a5

23The project structure now looks like this (check it under

Windows with tree / F and under Linux with tree):

[\ MeinWorkspace \ EthereumDemo]

- priv-geth.log

- start-test-Ethereum-Blockchain.bat

| - [private blockchain]

| - History

| - [geth]

||'- ...

'- [keystore]

'- UTC - 2018-01-22T09-50-58 ...

| - [solc]

| - msvcp140.dll

| - solc.exe

'- soltest.exe

'- [src]

- checkAllBalances.js

'-genesis-block.json

First smart contract: hello world demo

This demo shows:

-Like a simple one Solidity script for one Ethereum Smart Contract can look like.

-Like the Solidity script compiled and into the Ethereum blockchain deployed will.

-Like the Ethereum Smart Contract executed will.

In this demo, too, only command line tools are used. On graphical tools willfurther downreceived.

Follow the steps outlined below.

1.All above below Basic installations: Geth, Solc, private test Ethereum blockchainThe steps described must have been carried out.

2.Change to your EthereumDemo workspace directory set up above (e.g. \ MeinWorkspace \ EthereumDemo):