# 私链搭建

## 准备账户

进入工作目录 `/path/to/dxc/build/bin`下（本文'/path/to/dxc'指的是dxc源码的下载目录，在此之前，确保已经进行过编译，未编译参考：[编译和运行](/dxchain-wiki/zhong-wen-she-qu/kai-fa-zhe-wen-dang/kai-fa-zhe/bian-yi-he-yun-xing.md)）

```shell
$ ./geth account new --datadir ./data
```

新建账户的`keystore`文件位于 `/path/to/dxc/build/bin/data/keystore`文件夹下(过程如下)。

![](/files/vahI5J7Hbdmy4ep1qwlD)

将新地址导入metamask小狐狸钱包。

1. 首先进入导入页面

   ![](/files/Yi2gaZK0IAgWKw9GFigK)
2. 按照上图中标记顺序进行导入
   1. 选择导入方式为JSON 文件
   2. 选择新地址的keystore文件
   3. 填入创建新账户时的密码
   4. 点击导入（此处需要等待几十秒）
   5. 如果导入成功则会显示如下

      ![](/files/KHFqCDGAPwqfpPyDaeNg)

## 创建genesis.json

1. 在`/path/to/dxc/build/bin/`下创建genesis.json文件
2. 更换测试网`chainId` 为72(这里默认为72，则不需要改)。
3. 使用上面新账户（不带0x）替换 `extraData` 中的初始节点地址（注意：只替换中间40个地址字符）如下。

```
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000a88548e97af8809afac9dc7a930650c1179510590000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
===>>>
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000'your new account'0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
```

&#x20; 4\. 修改`alloc`中节点地址为自己的新地址，并配置初始余额。至少`0x50c783eb9b5c85f2a80000000。`

```json
{
    "config": {
        "chainId": 72,
        "homesteadBlock": 0,
        "eip150Block": 0,
        "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "eip155Block": 0,
        "eip158Block": 0,
        "byzantiumBlock": 0,
        "constantinopleBlock": 0,
        "petersburgBlock": 0,
        "istanbulBlock": 0,
        "muirGlacierBlock": 0,
        "dpos": {
            "period": 3,
            "epoch": 28800
        }
    },
    "nonce": "0x0",
    "timestamp": "0x5fc58968",
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000a88548e97af8809afac9dc7a930650c1179510590000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": "0x280de80",
    "difficulty": "0x1",
    "alloc": {
        "0xa88548e97af8809afac9dc7a930650c117951059": {
            "balance": "0x50c783eb9b5c85f2a80000000"
        }
    },
    "number": "0x0",
    "gasUsed": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
```

## 初始化创世块

```bash
$ ./geth init ./genesis.json --datadir ./data
```

## 开启节点

[运行](/dxchain-wiki/zhong-wen-she-qu/kai-fa-zhe-wen-dang/kai-fa-zhe/bian-yi-he-yun-xing.md#yun-hang)

## 开启挖矿

* 打开控制台 `./geth attach --datadir ./data`
* 解锁矿工账户 `personal.unlockAccount("miner address","password",0)`
* 开启挖矿 `miner.start()`

## 多节点挖矿

1. 其余节点使用相同的`genesis.json`初始化节点。
2. 获取主节点的enode信息`admin.nodeInfo`。
3. 新节点`geth attach` 打开控制台，添加主节点信息`admin.addPeer("enode info")`。


---

# 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://dxchain.gitbook.io/dxchain-wiki/zhong-wen-she-qu/kai-fa-zhe-wen-dang/kai-fa-zhe/si-lian-da-jian.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.
