安装操作系统:centos 7
#vi /etc/bashrc
#export PATH=$PATH:/mnt/go-ethereum/build/bin
#source /etc/bashrc
#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
#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
#curl -sL https://rpm.nodesource.com/setup_10.x | bash -
#yum install nodejs
#npm -v
#npm init -y
#npm install --sava [email protected]
//初始化过程
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());