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
  1. 第二个节点运行:
> geth --datadir data/01 init piccgenesis.json geth --datadir ./data/01 --networkid 147159025 --ipcdisable --port 56561 --rpcport 8201 --bootnodes "enode://95aecd889abf2c4809e28e815e21eb8531519763ec8913dbb450a71a094a874a4577d69907d9a63a6fa739402861048ee77881716bc53a7c4238635eaea93f71@192.168.10.139:56565" console

或者用新增节点的方式

> admin.addPeer("enode://c241145eb4c8ed3697a342625cfe48ced4a9f177036b0e965eab1af69343d67af84499f868e1820afab042f3f68d7630f175c894db153feb90180bad0d0c9b02@192.168.10.139:56565")
  1. 挖矿
> miner.start()
  1. 停止挖矿 --有延迟
> miner.stop()
  1. 转账  --后面为密码

解锁转账账户

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

转账到账户

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

查看转账情况

> eth.pendingTransactions
  1. 挖矿 挖出一个节点即可转账成功

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") #至此无法调用 参数有误

猜你喜欢

转载自blog.csdn.net/qq_29126023/article/details/84345040