扣丁学堂区块链2.0以太坊私有链搭建和geth客户端使用

  在2018年相信大多数都了解过区块链开发技术,它分为三个架构:1.0、2.0、3.0,今天我们讲的是区块链培训2.0技术以太坊私有链搭建和geth客户端使用的详细介绍。

  geth客户端的安装
  使用安装包安装
  sudoapt-getinstallsoftware-properties-common
  sudoadd-apt-repository-yppa:ethereum/ethereum
  sudoapt-getupdate
  sudoapt-getinstallethereum
  使用源码编译,搭建golang的环境
  1、先把go语言安装包下载wget
  2.执行sudotar-C/usr/local/-xzfgo1.8.3.linux-amd64.tar.gz解压
  3.vim~/.bashrc添加exportPATH=$PATH:/usr/local/go/bin然后在/home目录下建立workspace目录,添加go的工作目录exportGOPATH=/home/workspace,最后source~/.bashrc
  4.sudoapt-getinstallgit-y安装git进入workspace,建立github.com目录,github.com目录建立ethereum目录,在ethereum目录中执行gitclonehttps://github.com/ethereum/go-ethereum.git
  5.cdgo-ethereum执行makegeth
  创建私有链
  创建一个初始块
  vimgenesis.json
  {
  "nonce":"0x0000000000000042",
  "config":{
  "chainId":1123,
  "homesteadBlock":0,
  "eip155Block":0,
  "eip158Block":0
  },
  "timestamp":"0x0",
  "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData":"0x00",
  "gasLimit":"0x80000000",
  "difficulty":"0x10",
  "mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase":"0x3333333333333333333333333333333333333333",
  "alloc":{}
  }
  初始化创世块
  geth--datadir"qkl"--networkid1123initgenesis.json
  进入私有链
  geth--identity"qkl"--datadir"qkl"--networkid1123--rpc--port30303console2>>geth.log
  geth客户端的一些命令
  账户操作
  eth.accounts//查看账户
  personal.listAccounts//查看账户
  personal.newAccount("***")//新建账户
  personal.unlockAccount("**********")//解锁账户
  personal.lockAccount("**********")//锁定账户
  代币操作
  eth.getBalance()//查看余额
  web3.fromWei()//单位换算
  节点操作
  net模块
  net.listening//查看节点状态
  net.peerCount//查看节点链接的数量
  admin模块
  admin.nodeInfo//查看节点信息
  admin.addPeer()//添加节点
  admin.peers//查看添加的节点的信息
  eth模块
  eth.hashrate//查看节点的hash运算速率
  开启和关闭挖矿
  miner.start(n)//n是挖矿的线程数
  miner.stop()
  一些设置命令
  miner.setEtherbase(eth.accounts[n])//etherbase地址并不需要一定是本机上
  miner.setExtra("zhou")//写一些额外信息
  eth.getBlock(n)//查看区块信息
 

猜你喜欢

转载自blog.csdn.net/codingker/article/details/81096914