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 --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
- 第二個節點執行:
> geth --datadir data/01 init piccgenesis.json geth --datadir ./data/01 --networkid 147159025 --ipcdisable --port 56561 --rpcport 8201 --bootnodes "enode://95aecd889abf2c4809e28e815e21eb8531519763ec8913dbb450a71a094a874a4[email protected]192.168.10.139:56565" console
或者用新增節點的方式
> admin.addPeer("enode://c241145eb4c8ed3697a342625cfe48ced4a9f177036b0e965eab1af69343d67af[email protected]192.168.10.139:56565")
- 挖礦
> miner.start()
- 停止挖礦 --有延遲
> miner.stop()
- 轉賬 --後面為密碼
解鎖轉賬賬戶
> personal.unlockAccount(eth.accounts[0],'123')
轉賬到賬戶
> eth.sendTransaction({from: eth.accounts[0], to:"0x45d20f1ffdbb6ed5069cfe032d1ecae1e382fc40"}, value: web3.toWei(1, "ether"))
檢視轉賬情況
> eth.pendingTransactions
- 挖礦 挖出一個節點即可轉賬成功
go-ethereum專案地址
java的以太坊錢包應用開發 專案主要依賴:
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>3.2.0</version>
</dependency>
在控制檯呼叫智慧合約
> abi=<contract json>
> myContract=eth.contract(abi)
> myContract=myContract.at(<contract address>)
> myContract.say("okkpp") #至此無法呼叫 引數有誤