天天看點

Windows下運作以太坊節點、搭建私鍊、挖礦環境搭建搭建私鍊流程

環境搭建

安裝windows下的包管理工具chocolatey

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
           
C:\Windows\system32> choco install git
C:\Windows\system32> choco install golang
C:\Windows\system32> choco install mingw
           

during the commands below, you get the following message:

WARNING: The data being saved is truncated to 1024 characters. Then that means that the setx command will fail, and proceeding will truncate the Path/GOPATH. If this happens, it's better to abort, and try to make some more room in Path before trying again.

then

C:\Users\xxx> set "GOPATH=%USERPROFILE%"
C:\Users\xxx> set "Path=%USERPROFILE%\bin;%Path%"
C:\Users\xxx> setx GOPATH "%GOPATH%"
C:\Users\xxx> setx Path "%Path%"
           

這部分也很重要

C:\Users\xxx> mkdir src\github.com\ethereum
C:\Users\xxx> git clone https://github.com/ethereum/go-ethereum src\github.com\ethereum\go-ethereum
C:\Users\xxx> cd src\github.com\ethereum\go-ethereum
C:\Users\xxx> go get -u -v golang.org/x/net/context
           

Finally, the command to compile geth is:

C:\Users\xxx\src\github.com\ethereum\go-ethereum> go install -v ./cmd/geth
           

上面步驟可以替換cmd後面的路徑,安裝其他子產品。

搭建私鍊流程

建立配置檔案 在 /home/floder/下建立 piccgenesis.json ,内容如下:

{ "nonce":"0x0000000000000042", "mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000", "difficulty": "0x4000", "alloc": {}, "coinbase":"0x0000000000000000000000000000000000000000", "timestamp": "0x00", "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x", "gasLimit":"0xffffffff", "config": {} }

geth 參數詳解

1.主節點運作:

初始化

> geth --datadir ./data init piccgenesis.json
           

運作

> geth --datadir ./data --networkid 147159025 --rpc --port 56565 --rpcport 8200 console
           

cmd:

> geth --identity "PICCetherum" --rpc --rpccorsdomain "*" --datadir "%cd%\chain" --port "30303"  --rpcapi "db,eth,net,web3" --networkid 95518 console
           

powershell:

> geth --identity "PICCetherum" --rpc --rpccorsdomain "*" --datadir "chain" --port "30303"  --rpcapi "db,eth,net,web3" --networkid 95518 console
           

2.第二個節點運作:

> geth --datadir data/01 init piccgenesis.json geth --datadir ./data/01 --networkid 147159025 --ipcdisable --port 56561 --rpcport 8201 --bootnodes "enode://95aecd889abf2c4809e28e815e21eb8531519763ec8913dbb450a71a094a874a4577d69907d9a63a6fa739402861048[email protected]:56565" console
           

或者用新增節點的方式

> admin.addPeer("enode://c241145eb4c8ed3697a342625cfe48ced4a9f177036b0e965eab1af69343d67af84499f868e1820afab042f3[email protected]:56565")
           

3.1挖礦

> miner.start()
           

3.2停止挖礦 --有延遲

> miner.stop()
           

3.3轉賬  --後面為密碼

解鎖轉賬賬戶

> personal.unlockAccount(eth.accounts[0],'123')
           

轉賬到賬戶

> eth.sendTransaction({from: eth.accounts[0], to:"0x45d20f1ffdbb6ed5069cfe032d1ecae1e382fc40"}, value: web3.toWei(1, "ether"))
           

檢視轉賬情況

> eth.pendingTransactions
           

4.挖礦 挖出一個節點即可轉賬成功

go-ethereum項目位址

官方錢包下載下傳

java的以太坊錢包應用開發 項目主要依賴:

<dependency>
    <groupId>org.web3j</groupId>
    <artifactId>core</artifactId>
    <version>3.2.0</version>
</dependency>
           

參考資料.1

在控制台調用智能合約

> abi=<contract json>
> myContract=eth.contract(abi)
> myContract=myContract.at(<contract address>)
> myContract.say("okkpp") #至此無法調用 參數有誤
           

繼續閱讀