Création d'une blockchain Ethereum privée.

Distribution de travail : Ubuntu 18.04 Liens : https://www.une-blockchain.fr/ethereum-creer-une-blockchain-privee/ https://blog.webnet.fr/implementation-blockchain-privee-geth/

1/ Mise-à-jour de la distribution.

util01@station01:~$ sudo apt-get update && sudo apt-get upgrade

2/ Installation de Geth.

util01@station01:~$ sudo add-apt-repository -y ppa:ethereum/ethereum util01@station01:~$ sudo apt-get install ethereum

3/ Création d'un répertoire de travail.

util01@station01:~$ mkdir -p ETHEREUM/data util01@station01:~$ cd ETHEREUM/ util01@station01:~/ETHEREUM$

4/ Création du fichier de configuration.

Créer : ~/ETHEREUM/genesis.json Ajouter : { "nonce": "0x0000000000000042", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "difficulty": "0x20000", "alloc": {}, "coinbase": "0x0000000000000000000000000000000000000000", "timestamp": "0x0", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x", "gasLimit": "0xffffffff", "config": { "chainId": 7789, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0 } }

5/ Initialisation de la blockchain.

util01@station01:~/ETHEREUM$ geth --nousb --identity "hackcoin" --datadir "~/ETHEREUM/data" init genesis.json INFO [10-03|21:50:30.376] Maximum peer count ETH=50 LES=0 total=50 ... INFO [10-03|21:50:30.612] Successfully wrote genesis state database=lightchaindata hash="047862…906579"

6/ Démarrage de la blockchain.

util01@station01:~/ETHEREUM$ geth --datadir "~/ETHEREUM/data" --networkid 666 --http --http.port "8545" --http.corsdomain "*" --nodiscover --rpcapi="admin,eth,net,web3,personal,txpool,miner" --nousb --allow-insecure-unlock WARN [10-03|21:57:38.848] Sanitizing cache to Go's GC limits provided=1024 updated=664 ... INFO [10-03|21:57:39.054] HTTP server started endpoint=127.0.0.1:8545 cors=* vhosts=localhost

7/ Lancement de la console Javascript pour une connexion à la blockchain.

`util01@station01:~$ geth attach http://127.0.0.1:8545 Welcome to the Geth JavaScript console! instance: Geth/v1.9.22-stable-c71a7e26/linux-amd64/go1.15 at block: 0 (Thu Jan 01 1970 01:00:00 GMT+0100 (CET)) datadir: /home/util01/ETHEREUM/data modules: admin:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

`

8/ Affichage des informations sur la blockchain.

> admin.nodeInfo

9/ Création d'un compte.

`> personal.newAccount() Passphrase: Repeat passphrase: "0x32aa8d0e0141e924e8e487c5863642128c3e0221"

`

10/ Liste des comptes.

> eth.accounts ["0x32aa8d0e0141e924e8e487c5863642128c3e0221"]

11/ Récupérer la balance du compte.

`> eth.getBalance("0x32aa8d0e0141e924e8e487c5863642128c3e0221")

eth.getBalance(eth.accounts[0]) web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")`

12/ Minage.

- Définir le compte qui va miner :

> miner.setEtherbase(web3.eth.accounts[0]) true

- Lancement du minage :

> miner.start() null Attendre quelques minutes.

- Arrêter le minage :

`> miner.stop()

- Affichage du solde :

[sourcecode language="plain"]

eth.getBalance("0x32aa8d0e0141e924e8e487c5863642128c3e0221") 255000000000000000000 eth.getBalance(eth.coinbase) 290000000000000000000`

13/ Transfert d'Ether.

- Arrêter le minage :

> miner.stop() null

- Création d'un autre compte :

personal.newAccount() Passphrase: Repeat passphrase: "0x05683a17c9fd8488e340da80a08400ba610963d5"

- Liste des comptes :

> eth.accounts ["0x32aa8d0e0141e924e8e487c5863642128c3e0221", "0x05683a17c9fd8488e340da80a08400ba610963d5"]

- Solde de compte :

> eth.getBalance("0x05683a17c9fd8488e340da80a08400ba610963d5")

- Déverrouillage du compte source :

> personal.unlockAccount("0x32aa8d0e0141e924e8e487c5863642128c3e0221") Unlock account 0x32aa8d0e0141e924e8e487c5863642128c3e0221 Passphrase: true

- Transfert :

`> eth.sendTransaction({from: "0x32aa8d0e0141e924e8e487c5863642128c3e0221", to: "0x05683a17c9fd8488e340da80a08400ba610963d5", value: web3.toWei(1, "ether")}) "0x75592128b8c19c1181b9fe713713ab4dcf18f56c5291c1f84a307334256b83fc"

`

- Vérification :

> txpool.status { pending: 1, queued: 0 }

- Redémarrage du minage :

> miner.start() null Attendre quelques minutes.

- Vérification de la transation :

> txpool.status { pending: 0, queued: 0 } > eth.getBalance("0x32aa8d0e0141e924e8e487c5863642128c3e0221") 739000000000000000000 > eth.getBalance("0x05683a17c9fd8488e340da80a08400ba610963d5") 1000000000000000000