# 挖矿

### 欢迎windows用户尝试[一键挖矿](https://github.com/seeleteam/seele-one-click-mining/releases/latest)

* 使用说明参考zip中的readme.txt。

## 挖矿

### 下载

下载最新[可执行档和配置模板](https://github.com/seeleteam/go-seele/releases/latest)。zip文件夹格式如下：

```
mac/linux/win32_v#.#.#
├── node1.json //片1节点配置模板
├── node2.json //片2节点配置模板
├── node3.json //片3节点配置模板
├── node4.json //片4节点配置模板
└── build 
    ├── client //client可执行档：使用节点服务
    ├── discovery
    ├── light
    ├── node //node可执行档：启动节点
    ├── tool
    └── vm
```

以下操作用终端进入build文件夹内执行

### 账户

生成：根据片数生成公私钥对

```
$ ./client key --shard 1
public key:  0x43ff8ee89e56de149fd29bedbf8f3f4094cfe451
private key: 0x85c7d55a434037336a094575506229d82f771d14e9ba6e8c8ffc6e5c1f21de8a
```

验证：验证公钥或私钥理性和公私钥片数

```
$ ./client getshardnum --account 0x43ff8ee89e56de149fd29bedbf8f3f4094cfe451
shard number: 1
$ ./client getshardnum --privatekey 0x85c7d55a434037336a094575506229d82f771d14e9ba6e8c8ffc6e5c1f21de8a
shard number: 1
```

保存：密码、名称、私钥来生成keyfile

```
$ ./client savekey --privatekey 0x85c7d55a434037336a094575506229d82f771d14e9ba6e8c8ffc6e5c1f21de8a --file shard1account
Password:
Repeat password:
store key successfully, the key file path is shard1account
```

还原：用keyfile和密码还原私钥

```
$ ./client deckeyfile --file shard1account
Please input your key file password:
public key:  0x43ff8ee89e56de149fd29bedbf8f3f4094cfe451
private key: 0x85c7d55a434037336a094575506229d82f771d14e9ba6e8c8ffc6e5c1f21de8a
```

### 配置 node.json

1. 修改挖矿账户
   * 若在片1挖矿，要生成片1的公私钥对，并将片1公钥填入node1.json节点配置模板。
   * 若在片2挖矿，要生成片2的公私钥对，并将片2公钥填入node2.json节点配置模板。
   * 片3、4以此类推。
2. 修改节点id
   * 生成公私钥对，片数无所谓，取私钥填入挖矿所用的配置文档。

片1挖矿配置节点例子：

配置前

```
{
  "basic":{
    ...
    "coinbase": "0xcee66ad4a1909f6b5170dec230c1a69bfc2b21d1", ← 挖矿公钥
    ...
  },
  "p2p": {
    "privateKey": "0xf65e40c6809643b25ce4df33153da2f3338876f181f83d2281c6ac4a987b1479", ← 节点id
    ...
  },
  ...
}
```

配置后

```
{
  "basic":{
    ...
    "coinbase": "0x43ff8ee89e56de149fd29bedbf8f3f4094cfe451", ← 片1公钥
    ...
  },
  "p2p": {
    "privateKey": "0xa12b2ef3e40389ef2e0e3130a88674071760a283c5ed53dfeae40a10cdedb9a8", ← 片2私钥
    ...
  },
  ...
}
```

### 启动 node 挖矿

启动挖矿节点：线程数12，用node1.json的配置文档

```
./node start -c ../node1.json --threads 12
```

启动节点、不挖矿：

```
./node start -c ../node1.json -m stop
```

### 使用 node 服务

每次节点启动会先检查本地数据库完整性，每秒10000块左右。之后会启动节点服务，用户可以用client来使用各种服务。

* 片1的监听端口：8027
* 片2的监听端口：8028
* 片3的监听端口：8029
* 片4的监听端口：8026

余额：

```
$ ./client getbalance --account 0x43ff8ee89e56de149fd29bedbf8f3f4094cfe451 -a 104.218.164.169:8027
{
        "Account": "0x43ff8ee89e56de149fd29bedbf8f3f4094cfe451",
        "Balance": 0 ←余额，单位为fan，1seele=1亿fan
}
```

节点信息：

```
$ ./client getinfo -a 127.0.0.1:8027
{
        "BlockAge": 54, ←最高块距今秒数
        "Coinbase": "0x43ff8ee89e56de149fd29bedbf8f3f4094cfe451", ←挖矿账户
        "CurrentBlockHeight": 1225756, ←高度
        "HeaderHash": "0xa12b2ef3e40389ef2e0e3130a88674071760a283c5ed53dfeae40a10cdedb9a8", ←节点id
        "MinerStatus": "Stopped", ←是否在挖矿
        "PeerCnt": "162 (19 54 45 44)", ←连接总节点数（来自片1 2 3 4）
        "Shard": 1, ←片数
        "Version": "v1.2.4" ←版本
}
```

直接打`./client`可见可用命令，用`-h`查看命令使用方法，如`./client sendtx -h`查看如何用keyfile做交易。

## 编译 node

以下示例为ubuntu和mac命令，

### 检查git，gcc，go版本

```bash
$ git --version
git version 2.17.1

$ gcc --version
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
​
$ go version
go version go1.10.4 linux/amd64
```

### 下载go-seele

下载go-seele：首先在根目录里创建路径：\~/go/src/github.com/seeleteam。

```bash
~$ cd
~$ mkdir -p go/src/github.com/seeleteam
~$ cd go/src/github.com/seeleteam
~/go/src/github.com/seeleteam$ git clone https://github.com/seeleteam/go-seele.git

Cloning into 'go-seele'...
remote: Enumerating objects: 53, done.
remote: Counting objects: 100% (53/53), done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 10032 (delta 13), reused 15 (delta 4), pack-reused 9979
Receiving objects: 100% (10032/10032), 12.25 MiB | 18.45 MiB/s, done.
Resolving deltas: 100% (5804/5804), done.
```

### 编译go-seele：

```bash
~/go/src/github.com/seeleteam$ cd go-seele
~/go/src/github.com/seeleteam/go-seele$ make all
go build -o ./build/discovery ./cmd/discovery
Done discovery building
go build -o ./build/node ./cmd/node 
Done node building
go build -o ./build/client ./cmd/client
Done full node client building
go build -o ./build/light ./cmd/client/light
Done light node client building
go build -o ./build/tool ./cmd/tool
Done tool building
go build -o ./build/vm ./cmd/vm
Done vm building
~/go/src/github.com/seeleteam/go-seele$
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seeletech.gitbook.io/wiki/cn/wa-kuang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
