挖矿节点计算机的第二个任务是真正的挖矿,即进行加密哈希计算,解决一个计算难题,进行算力竞争。在众多争夺记账权的节点中,谁完成这个计算,它打包的区块就被加到了区块链的最后,成为最新的区块。率先完成计算的矿工会赢得新区块的挖矿奖励。最初,成功挖出一个区块,矿工可以获得50个比特币的奖励,按规则,这个挖矿奖励每四年减半一次,分别为25个、12.5个,以此类推。
#以太坊私网建立、合约编译、部署完全教程(1)
##一、为什么用到私有链?
在以太坊的共有链上部署智能合约、发起交易需要花费以太币。而通过修改配置,可以在本机搭建一套以太坊私有链,因为与公有链没关系,既不用同步公有链庞大的数据,也不用花钱购买以太币,很好地满足了智能合约开发和测试的要求,开发好的智能合约也可以很容易地切换接口部署到以太坊公有链上。
##二、开源工具和语言
###1、[brew](https://brew.sh/)MacOS包管理器
拷贝下面的命令到终端,然后回车。
```
/usr/bin/ruby-e"$(curl-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
###2、install Go compiler
```
liyuechun:Downloads yuechunli$brew install go
```
###3、[geth](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum)运行以太坊节点
下载[Source code(tar.gz)](https://github.com/ethereum/go-ethereum/archive/v1.5.9.tar.gz)
```
liyuechun:Downloads yuechunli$cd go-ethereum-1.5.9
liyuechun:go-ethereum-1.5.9 yuechunli$pwd
/Users/liyuechun/Downloads/go-ethereum-1.5.9
liyuechun:go-ethereum-1.5.9 yuechunli$make geth
```
###4、[Solidity](https://solidity.readthedocs.io/en/develop/)以太坊智能合约语言
```
brew update
brew upgrade
brew tap ethereum/ethereum
brew install solidity
brew linkapps solidity
```
**备注:**安装时间可能有点长,请耐心等待...
**备注:**安装时间可能有点长,请耐心等待...
**备注:**安装时间可能有点长,请耐心等待...
如果碰见下面的错误,请移步:[http://blog.csdn.net/Sico2Sico/article/details/71082130](http://blog.csdn.net/Sico2Sico/article/details/71082130)
```
The GitHub credentials in the macOS keychain may be invalid.
Clear them with:
printf"protocol=httpsnhost=github.comn"|git credential-osxkeychain erase
Or create a personal access token:
https://github.com/settings/tokens/new?scopes=gist,public_repo&description=Homebrew
```
##三、建立私链
####1.创建一个文件夹来存储你的私链数据
```
liyuechun:1015 yuechunli$mkdir privatechain
liyuechun:1015 yuechunli$pwd
/Users/liyuechun/Desktop/1015
liyuechun:1015 yuechunli$ls
privatechain
liyuechun:1015 yuechunli$
```
####2.使用`geth`来加载
```
geth--networkid 123--dev--datadir data1--rpc--rpcaddr 192.168.1.5--rpcport 8989--port 3000
```
**各选项含义如下:**
-`--identity:`指定节点ID;
-`--rpc:`表示开启HTTP-RPC服务;
-`--rpcaddr:`HTTP-RPC服务ip地址;
-`--rpcport:`指定HTTP-RPC服务监听端口号(默认为8545);
-`--datadir:`指定区块链数据的存储位置;
-`--port:`指定和其他节点连接所用的端口号(默认为30303);
-`--nodiscover:`关闭节点发现机制,防止加入有同样初始配置的陌生节点。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70016646/viewspace-2948587/ ,如需转载,请注明出处,否则将追究法律责任。