windows 以太坊ethereum 私链搭建

一、安装 以太坊 客户端

1、https://github.com/ethereum/go-ethereum/wiki/Installation-instructions-for-Windows

按照流程安装好客户端。

 

2、配置  geesis.json

a.在Ethereum 目录下新建data文件夹

windows 以太坊ethereum 私链搭建_第1张图片

b.在Ethereum 目录下新建文件 genesis.json (初始化创世块)

 

{
  "config": {
        "chainId": 10,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x02000000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

c.在Ethereum 目录下打开命令行运行

 

 

geth --datadir "data" init genesis.json

二、交易、挖矿

 

1、操作geth

在 Ethereum 目录打开命令行

 

geth --datadir "data" --rpc --rpccorsdomain "*" --rpcaddr "0.0.0.0"  --rpcapi "eth,net,web3" --port 0 console

如果报错 

 

 

Fatal: Error starting protocol stack: Access is denied

那么尝试添加  --ipcdisable

 

 

geth --datadir "data" --rpc --rpccorsdomain "*" --rpcaddr "0.0.0.0"  --rpcapi "eth,net,web3" --ipcdisable --port 0 console

没有出现错误则geth启动成功

 

 

*注:博主这里禁用 ipc (使用了 --ipcdisable ),所以不能同时多个cmd运行geth

 

 

2、给第一个用户充值,则修改 genesis.json 为

 

{
	"config": {
        "chainId": 10,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "nonce":"0x0000000000000042",
    "mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",
    "difficulty": "0x4000",
    "alloc": {
		"0x81f9477fdeef4d3b5a5acd980be2218c659040a7":{
			"balance":"0x100000000000000000000000000"
		}
	},
    "coinbase":"0x0000000000000000000000000000000000000000",
    "timestamp": "0x00",
    "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x0000000000000000000000000000000000000000000000000000000001",
    "gasLimit":"0xffffffff"
}

 

 

3、基本操作

 

a.查询所有用户

 

eth.accounts;

b.创建新用户

 

 

personal.newAccount('000000');

c.查询用户余额

 

 

eth.getBalance(eth.accounts[1]);

d.解锁用户

 

 

personal.unlockAccount(eth.coinbase, '000000', 860000);

:1、eth.coinbase 同 eth.accounts[0]

 

2、'000000' 为用户密码,860000 为解锁时间

e.用户转账

 

eth.sendTransaction({from:eth.coinbase,to:eth.accounts[1],value:10000,gas:21000});

:gas 为 交给矿工的燃油费,意为 交易手续费

 

f.开始挖矿

 

 miner.start();

d.停止挖矿

 

 

miner.stop();

 

 

 

 

 


 

 

 

你可能感兴趣的:(ethereum)