安装geth
然后启动:

  1. build/bin/geth --rpcapi "db,eth,net,web3" --rpcport "8545" --datadir "/Users/shaohua/data/ethereum" --rpc --rpccorsdomain "*" --networkid 5266 --verbosity 5 --bootnodes=none --nodiscover console
  • —identity 指定节点ID
  • —networkid 是网络id,区分各方区块链的网络id
  • —dev 开发
  • —datadir 创建私链数据存储目录
  • —rpc 表示开启HTTP-RPC服务
  • —rpcaddr HTTP-RPC服务ip地址
  • —rpcport HTTP-RPC服务监听端口号(default:8545)
  • —port 指定和其他节点连接所用的端口号(default:30303)
  • —nodiscover 关闭节点发现机制,防止加入有同样初始配置的陌生节点
    然后解锁账号:
    1. personal.unlockAccount(eth.coinbase)
    设置挖矿账号:
    1. miner.setEtherbase(eth.coinbase)
    然后用geth通过datadir下的geth.ipc文件进入console
    1. geth attach ipc:geth.ipc
    开启挖矿:
    1. miner.start();
    安装truffle
    然后启动truffle console:
    1. web3.eth.getBlock("pending").gasLimit //获取挖矿限制
    把gasLimit的值填入truffle.js中的gas,如下:
    1. module.exports = {
    2. networks: {
    3. development: {
    4. host: "127.0.0.1",
    5. port: 8545,
    6. gas: 4712388,
    7. network_id: 5266 // Match any network id
    8. },
    9. }
    10. }
    然后就可以通过truffle compile编译后,truffle migrate发布合约了。
    truffle migrate --reset用于覆盖原来的发布

打开一个正在运行的节点:

  1. cd /home/jianhuaixie/blockchain/privateChain/data1 //存放数据的地方
  2. geth attach ipc:geth.ipc

参考:
http://www.sites-help.com/renwu/1586197925_zh.html
https://www.jianshu.com/p/7b7235a6c3e6

分类: web

标签:   ethereum