geth 命令

下载go-ethereum 
git clone https://github.com/ethereum/go-ethereum.git
cd  go-ethereum
git checkout v1.7.2
make geth
make all

2.geth --datadir chain1 init genesis.json 创建创世块
3.启动JS 控制台
geth --datadir "./chain1" --nodiscover console 2>>geth.log
--nodiscover 使用这个参数,你的节点就不会被其他人发现,除非手动添加你的节点。否则,就只有一个被无意添加到一个陌生区块链上的机会,
 那就是跟你有相同的genesis文件和networkID。
--maxpeers 0 如果你不想有人连上你的测试链,就用maxpeers 0。或者,你可以调整参数,当你确切的知道有几个节点要连接上来的时候。
--rpc 允许RPC操作你的节点。这个参数在Geth上是默认的。
--rpcapi "db,eth,net,web3" 这个命令指示了允许通过RPC访问的命令。默认情况下,Geth允许web3。
--rpcport "8080"
--rpccorsdomain "http://chriseth.github.io/browser-solidity/"
--datadir "/home/TestChain1" 私有链存放路径(最好跟公有链路径不同)
--port "30303" 网络监听端口,用来和其他节点手动连接
--identity “TestnetMainNode" 用来标识你的节点的,方便在一大群节点中识别出自己的节点
4.创建账户
personal.newAccount("123456")
5.查看账户

eth.accounts,也可以写成 web3.eth.accounts。因为它实际上市web3对象的一部分

检查所有账户的余额,创建JS函数

function checkAllBalances() {

    web3.eth.getAccounts(function(err, accounts) {

        accounts.forEach(function(id) {

            web3.eth.getBalance(id, function(err, balance) {

                console.log("" + id + ":\tbalance: " + web3.fromWei(balance,  "ether") + " ether");

            });

        });

    });

});

执行上述行后,需要调用以下函数检查所有余额

checkAllBalances()

可以将这种方便的小工具放入到一个保存到文件中,并使用loadScript一次性加载

loadScript('F:/Geth/some/script/checkAllBalance.js')

6.查看区块高度
eth.blockNumber
7.查看区块信息
eth
eth.getBlock(0) //查看创始区块信息
8.启动挖矿
miner.start() ;miner.start(1) 表示仅以一个线程挖矿
私有链的第一个交易区块中的交易是怎么来的???
9.停止挖矿

miner.stop()

10.查看当前节点信息

admin.nodeInfo //查看当前节点信息

admin.nodeInfo.enode  // 自己节点的URL,在其他的客户端上执行admin.addPeer("自己节点的URL")告诉它们添加自己的节点

11.Generating DAG in process 是什么?

首次挖矿会产生DAG文件

12.两个账户之间转账
eth.getBalance(eth.accounts[0]) #查看余额
personal.unlockAccount(eth.accounts[0],"123456")#转账之前解锁账户
web3.eth.sendTransaction({from:eth.accounts[0],to:accounts[1],value:web3.toWei(1,"ether")}) #转账(转入账户和转出账户都要解锁)
13.转账之后要挖矿才可以
miner.start() miner.stop()

14.节点主账户

eth.coinbase

15

 

猜你喜欢

转载自blog.csdn.net/liudaoqiang_tj/article/details/81023582