以太坊go-ethereum 安装教程(Building from source)

安装操作系统:centos 7

  1. # yum install git
  2. # git clone https://github.com/ethereum/go-ethereum
  3. Building geth requires Go and C compilers to be installed:
  4. #yum install -y golang
  5. #cd go-ethereum #make geth

 

  • 添加geth到环境变量

#vi /etc/bashrc

#export PATH=$PATH:/mnt/go-ethereum/build/bin

#source /etc/bashrc

 

  •  创建geth目录

#mkdir geth

#cd geth

#mkdir db

  • 创建创世节点初始文件

#vi gensis.json

{

   "config":{

    "chainID":2018,

    "homesteadBlock":0,

    "eip155Block":0,

    "eip158Block":0

  },

  "alloc":{"0x1667b9bf214edd9143824a14f101968e1cb35ba5":{"balance":"10000000000000000000000000000000"}},

  "coinbase":"0x0000000000000000000000000000000000000000",

  "difficulty":"0x01",

  "extraData":"0x7777777777777777",

  "gasLimit":"0xffffffff",

  "nonce":"0x0000000000000001",

  "mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",

  "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",

  "timestamp":"0x00"

}

 

  • 初始化创世节点

 

#geth --datadir db init gensis.json

 

  • 进入JavaScript控制台

#geth --datadir db --networkid 2018 console

#启动节点

#geth --datadir db --rpc --rpcaddr=0.0.0.0 --rpcport 8545 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,admin,ssh,txpool,debug,miner" --nodiscover --maxpeers 30 --networkid 2018 --port 30303 --mine --minerthreads 1 --etherbase "0x229540cbb3a429c6539a78cf0260b8e543c74404" console

 

#进入一个运行节点的console端

#geth --datadir db --networkid 2018 console

#账户1

#0x1667b9bf214edd9143824a14f101968e1cb35ba5

账户2

#0xd493c565090d27edfc90b037c4e9344c67af30ea

 

  • #新建账户

#personal.newAccount("235681")

 

  • 查看所有账户

#eth.accounts

 

  • #查看账户余额

#balance=web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")

 

  • #设置挖矿地址

# miner.setEtherbase(eth.accounts[0])

  • #查看是否成功

#eth.coinbase

  • #启动挖矿

#miner.start(1)

  • #停止挖矿

#miner.stop()

 

 

 

 

 

  • 远程管理节点
  • 查看节点信息

#admin.nodeInfo

 

  • 添加其他节点

#admin.addPeer()

  •  

 

以太坊的编程接口

6.1 web3.js APIAPI

  • #安装nodejs

#curl -sL https://rpm.nodesource.com/setup_10.x | bash -

#yum install nodejs

#npm -v

#npm init -y

#npm install --sava web3@0.20.0

 

 

 

 

  • #查看账户
//初始化过程
var Web3 = require('web3');

if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
var version = web3.version.api;
console.log(version);
// 查看节点所有可用账号
var accounts = web3.eth.accounts;
console.info(accounts);
//查看账户余额
var balance_1 = web3.eth.getBalance(web3.eth.accounts[0]);
var balance_eth = web3.fromWei(balance_1,'ether');
console.info(balance_eth.toString());

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东方浮尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值